Commit 089edf49 authored by Jose Borreguero's avatar Jose Borreguero
Browse files

improve docs and formating, minor bugfix



Signed-off-by: default avatarJose Borreguero <borreguero@gmail.com>
parent f6b1043b
......@@ -73,8 +73,8 @@ private:
API::ITableWorkspace_sptr m_peakHeightTable{nullptr};
std::vector<double> m_peaksInDspacing;
std::map<detid_t, size_t> m_detidToRow;
double m_tofMin{0.};
double m_tofMax{0.};
double m_tofMin{0.}; // first bin boundary when rebinning in TOF (user input)
double m_tofMax{0.}; // last bin boundary when rebinning in TOF (user input)
double m_tzeroMin{0.};
double m_tzeroMax{0.};
double m_difaMin{0.};
......
......@@ -39,7 +39,7 @@ void calculateFromOffset(API::Progress &progress,
}
}
// look through the columns of detid and difc and put it into the
// look through the columns of detid and difc and copy theminto the
// SpecialWorkspace2D
void calculateFromTable(API::Progress &progress,
DataObjects::SpecialWorkspace2D &outputWs,
......@@ -100,15 +100,15 @@ void CalculateDIFC::init() {
declareProperty(std::make_unique<WorkspaceProperty<API::ITableWorkspace>>(
"CalibrationWorkspace", "", Direction::Input,
Mantid::API::PropertyMode::Optional),
"Optional: A OffsetsWorkspace containing the calibration "
"offsets. This cannot be specified with an "
"OffsetsWorkspace.");
"Optional: A TableWorkspace containing the DIFC values, "
"which will be copied. This property cannot be set in "
"conjunction with property OffsetsWorkspace.");
declareProperty(std::make_unique<WorkspaceProperty<OffsetsWorkspace>>(
"OffsetsWorkspace", "", Direction::Input,
Mantid::API::PropertyMode::Optional),
"Optional: A OffsetsWorkspace containing the calibration "
"offsets. This cannot be specified with a "
"CalibrationWorkspace.");
"offsets. This property cannot be set in conjunction with "
"property CalibrationWorkspace.");
}
std::map<std::string, std::string> CalculateDIFC::validateInputs() {
......@@ -139,6 +139,8 @@ void CalculateDIFC::exec() {
API::MatrixWorkspace_sptr outputWs = getProperty("OutputWorkspace");
if ((!bool(inputWs == outputWs)) ||
// SpecialWorkspace2D is a Workspace2D where each spectrum
// has one detector pixel, one X-value, and one Y-value.
(!bool(std::dynamic_pointer_cast<SpecialWorkspace2D>(outputWs)))) {
outputWs = std::dynamic_pointer_cast<MatrixWorkspace>(
std::make_shared<SpecialWorkspace2D>(inputWs->getInstrument()));
......@@ -153,7 +155,8 @@ void CalculateDIFC::exec() {
if (bool(calibWs)) {
calculateFromTable(progress, *outputSpecialWs, *calibWs);
} else {
// this method handles calculating from instrument geometry as well
// this method handles calculating from instrument geometry as well,
// and even when OffsetsWorkspace hasn't been set
const auto &detectorInfo = inputWs->detectorInfo();
calculateFromOffset(progress, *outputSpecialWs, offsetsWs.get(),
detectorInfo);
......
This diff is collapsed.
......@@ -43,6 +43,8 @@ private:
void generateDetidToIndex();
bool tableHasColumn(const std::string &ColumnName) const;
// minimum of (CalibrationWorkspace_row_count,
// GroupingWorkspace_histogram_count, MaskWorkspace_histogram_count)
std::size_t m_numValues{0};
API::ITableWorkspace_sptr m_calibrationWS;
std::map<detid_t, size_t> m_detidToIndex;
......
......@@ -249,10 +249,11 @@ void LoadDiffCal::makeMaskWorkspace(const std::vector<int32_t> &detids,
wksp->mutableRun().addProperty("Filename", m_filename);
for (size_t i = 0; i < numDet; ++i) {
bool shouldUse = (use[i] > 0);
bool shouldUse = (use[i] > 0); // true if detector is calibrated
auto detid = static_cast<detid_t>(detids[i]);
// in maskworkspace 0=use, 1=dontuse
wksp->setMasked(detid, !shouldUse);
// The mask value is 0 if the detector is good for use
wksp->setValue(detid, (shouldUse ? 0. : 1.));
progress.report();
}
......@@ -539,7 +540,7 @@ void LoadDiffCal::exec() {
if (groups.empty())
groups.assign(detids.size(), 1); // all go to one spectrum
if (use.empty())
use.assign(detids.size(), 1); // use everything
use.assign(detids.size(), 1); // all detectors are good, use them
if (difa.empty())
difa.assign(detids.size(), 0.); // turn off difa
if (tzero.empty())
......
......@@ -63,12 +63,12 @@ void SaveDiffCal::init() {
declareProperty(
std::make_unique<WorkspaceProperty<GroupingWorkspace>>(
"GroupingWorkspace", "", Direction::Input, PropertyMode::Optional),
"Optional: An GroupingWorkspace workspace giving the grouping info.");
"Optional: A GroupingWorkspace giving the grouping info.");
declareProperty(
std::make_unique<WorkspaceProperty<MaskWorkspace>>(
"MaskWorkspace", "", Direction::Input, PropertyMode::Optional),
"Optional: An Workspace workspace giving which detectors are masked.");
"Optional: A MaskWorkspace giving which detectors are masked.");
declareProperty(
std::make_unique<FileProperty>("Filename", "", FileProperty::Save, ".h5"),
......@@ -91,12 +91,12 @@ std::map<std::string, std::string> SaveDiffCal::validateInputs() {
getProperty("GroupingWorkspace");
if (bool(groupingWS) && numRows < groupingWS->getNumberHistograms()) {
result["GroupingWorkspace"] =
"Must have same number of spectra as the table has rows";
"Must have equal or less number of spectra as the table has rows";
}
MaskWorkspace_const_sptr maskWS = getProperty("MaskWorkspace");
if (bool(maskWS) && numRows < maskWS->getNumberHistograms()) {
result["MaskWorkspace"] =
"Must have same number of spectra as the table has rows";
"Must have equal or less number of spectra as the table has rows";
}
}
}
......@@ -104,22 +104,45 @@ std::map<std::string, std::string> SaveDiffCal::validateInputs() {
return result;
}
/**
* Create a dataset under a given group with a given name
* Use CalibrationWorkspace to retrieve the data
*
* @param group :: group parent to the dataset
* @param name :: column name of CalibrationWorkspace, and name of the dataset
*/
void SaveDiffCal::writeDoubleFieldFromTable(H5::Group &group,
const std::string &name) {
auto column = m_calibrationWS->getColumn(name);
// cppcheck-suppress compareBoolExpressionWithInt
// Retrieve only the first m_numValues, not necessarily the whole column
auto data = column->numeric_fill<>(m_numValues);
H5Util::writeArray1D(group, name, data);
}
/**
* Create a dataset under a given group with a given name
* Use CalibrationWorkspace to retrieve the data.
*
* @param group :: group parent to the dataset
* @param name :: column name of CalibrationWorkspace, and name of the dataset
*/
void SaveDiffCal::writeIntFieldFromTable(H5::Group &group,
const std::string &name) {
auto column = m_calibrationWS->getColumn(name);
// Retrieve only the first m_numValues, not necessarily the whole column
auto data = column->numeric_fill<int32_t>(m_numValues);
H5Util::writeArray1D(group, name, data);
}
// TODO should flip for mask
/**
* Create a dataset under a given group with a given name
* Use GroupingWorkspace or MaskWorkspace to retrieve the data.
*
* @param group :: group parent to the dataset
* @param name :: column name of the workspace, and name of the dataset
* @param ws :: pointer to GroupingWorkspace or MaskWorkspace
*/
void SaveDiffCal::writeIntFieldFromSVWS(
H5::Group &group, const std::string &name,
const DataObjects::SpecialWorkspace2D_const_sptr &ws) {
......@@ -130,14 +153,15 @@ void SaveDiffCal::writeIntFieldFromSVWS(
if (bool(ws)) {
for (size_t i = 0; i < m_numValues; ++i) {
auto &ids = ws->getSpectrum(i).getDetectorIDs();
auto found = m_detidToIndex.find(*(ids.begin()));
auto &ids = ws->getSpectrum(i).getDetectorIDs(); // set of detector ID's
// check if the first detector ID in the set is in the calibration table
auto found = m_detidToIndex.find(*(ids.begin())); // (detID, row_index)
if (found != m_detidToIndex.end()) {
auto value = static_cast<int32_t>(ws->getValue(found->first));
// in maskworkspace 0=use, 1=dontuse - backwards from the file
if (isMask) {
if (value == 0)
value = 1;
value = 1; // thus "use" means a calibrated detector, good for use
else
value = 0;
}
......@@ -178,6 +202,8 @@ void SaveDiffCal::exec() {
MaskWorkspace_const_sptr maskWS = getProperty("MaskWorkspace");
std::string filename = getProperty("Filename");
// initialize `m_numValues` as the minimum of (CalibrationWorkspace_row_count,
// GroupingWorkspace_histogram_count, MaskWorkspace_histogram_count)
m_numValues = m_calibrationWS->rowCount();
if (bool(groupingWS) && groupingWS->getNumberHistograms() < m_numValues) {
m_numValues = groupingWS->getNumberHistograms();
......@@ -196,6 +222,8 @@ void SaveDiffCal::exec() {
auto calibrationGroup =
H5Util::createGroupNXS(file, "calibration", "NXentry");
// write the d-spacing to TOF conversion parameters for the selected pixels
// as datasets under the NXentry group
this->writeDoubleFieldFromTable(calibrationGroup, "difc");
this->writeDoubleFieldFromTable(calibrationGroup, "difa");
this->writeDoubleFieldFromTable(calibrationGroup, "tzero");
......@@ -209,12 +237,14 @@ void SaveDiffCal::exec() {
this->writeIntFieldFromSVWS(calibrationGroup, "group", groupingWS);
this->writeIntFieldFromSVWS(calibrationGroup, "use", maskWS);
// check if the input calibration table has an "offset" field
if (this->tableHasColumn("offset")) // optional field
this->writeDoubleFieldFromTable(calibrationGroup, "offset");
else
g_log.information("Not writing out values for \"offset\"");
// get the instrument information
// get the instrument information only if a GroupingWorkspace or
// MaskWorkspace is supplied by the user
std::string instrumentName;
std::string instrumentSource;
if (bool(groupingWS)) {
......
......@@ -52,7 +52,7 @@ the instrument you don't want to use to align the sample/source
position (*e.g.* in the *Align sample position in POWGEN* usage
example below).
The source and sample positions (in that order) are aligned before an
The source and sample positions (in that order) are aligned before any
components are aligned.
Usage
......
......@@ -22,9 +22,10 @@ This is used in the equation
This algorithm uses the same underlying calculation as :ref:`algm-ConvertUnits`
and :ref:`algm-AlignDetectors`.
When specifying the ``CalibrationWorkspace``, this algorithm uses the
values in the ``detid`` and ``difc`` columns of the calibration
only. It ignores any other calibration constants.
When specifying the ``CalibrationWorkspace``, this algorithm copies the
values in the ``detid`` and ``difc`` columns of the calibration workspace.
It ignores any other calibration constants, such as ``difa`` and
``tzero`` (for more information, see the :ref:`DiffractionCalibrationWorkspace` concept page).
Assumptions: There are no assumptions and this algorithm works on the results
of :ref:`algm-LoadEmptyInstrument`.
......
......@@ -17,8 +17,9 @@ This algorithm calibrates the detector pixels and creates a
calibration is done in TOF not d spacing. The peak d values are
converted to TOF based on either the old calibration or the instrument
geometry. The ``InputWorkspace`` contains the data from a standard
sample. The results are then fitted with up to (in order) difc, t_zero and difa,
these values are details in :ref:`algm-AlignDetectors`.
sample. The results are then fitted with up to (in order) ``difc``,
``t_zero``, and ``difa``. These values are described in detail
in :ref:`algm-AlignDetectors`.
The peak fitting properties are explained in more detail in
:ref:`algm-FitPeaks`. This is used to perform a refinement of peaks
......
......@@ -12,7 +12,22 @@ Description
This algorithm saves a :ref:`diffraction calibration workspace
<DiffractionCalibrationWorkspace>`, ``MaskWorkspace``, and
``GroupingWorkspace`` from a hdf5 file.
``GroupingWorkspace`` to a HDF5 file.
The hierarchy of the HDF5 file is as follows:
calibration
+__ _detid
+__ _dasid (only if present in CalibrationWorkspace)
+__ _difc
+__ _difa
+__ _tzero
+__ _group
+__ _use ("0" if detector is not successfully calibrated, "1" otherwise)
+__ _offset (only if present in CalibrationWorkspace)
+__ _instrument
+-- name
+-- instrument_source (absolute path to the instrument definition file)
.. categories::
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment