Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
bc302d25
Commit
bc302d25
authored
Jun 29, 2021
by
Walsh, Michael
Browse files
implemented, doc'd, and added tests combindiffcal
parent
d47c3861
Changes
4
Hide whitespace changes
Inline
Side-by-side
Framework/Algorithms/inc/MantidAlgorithms/CombineDiffCal.h
View file @
bc302d25
...
...
@@ -12,7 +12,8 @@
namespace
Mantid
{
namespace
Algorithms
{
/** CombineDiffCal : TODO: DESCRIPTION
/** CombineDiffCal : Calibrate groups of pixels after cross correlation so that diffraction peaks can be adjusted to the
* correct positions
*/
class
MANTID_ALGORITHMS_DLL
CombineDiffCal
:
public
API
::
Algorithm
{
public:
...
...
Framework/Algorithms/src/CombineDiffCal.cpp
View file @
bc302d25
...
...
@@ -6,6 +6,7 @@
// SPDX - License - Identifier: GPL - 3.0 +
#include
"MantidAlgorithms/CombineDiffCal.h"
#include
"MantidAPI/SpectrumInfo.h"
#include
"MantidAPI/TableRow.h"
#include
"MantidDataObjects/OffsetsWorkspace.h"
#include
"MantidDataObjects/TableWorkspace.h"
...
...
@@ -58,12 +59,42 @@ std::map<std::string, std::string> CombineDiffCal::validateInputs() {
return
results
;
}
// Per Pixel:
//
// DIFC{eff} = (DIFC{pd}/DIFC{arb}) * DIFC{prev}
//
// DIFC{eff} = Output of this Alg, the combined DIFC
// DIFC{pd} = The DIFC produced by PDCalibration, found in the "GroupedCalibration"
// DIFC{arb} = found in the "CalibrationWorkspace" param
// DIFC{prev} = The previous DIFCs, found in "PixelCalibration", as per description this was the set generated by CC
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void
CombineDiffCal
::
exec
()
{
// TODO Auto-generated execute stub
const
DataObjects
::
Workspace2D_sptr
calibrationWS
=
getProperty
(
"CalibrationWorkspace"
);
const
DataObjects
::
TableWorkspace_sptr
groupedCalibrationWS
=
getProperty
(
"GroupedCalibration"
);
const
DataObjects
::
TableWorkspace_sptr
pixelCalibrationWS
=
getProperty
(
"PixelCalibration"
);
DataObjects
::
TableWorkspace_sptr
outputWorkspace
=
std
::
make_shared
<
DataObjects
::
TableWorkspace
>
();
outputWorkspace
->
addColumn
(
"int"
,
"detid"
);
outputWorkspace
->
addColumn
(
"double"
,
"difc"
);
Mantid
::
API
::
TableRow
groupedCalibrationRow
=
groupedCalibrationWS
->
getFirstRow
();
Mantid
::
API
::
TableRow
pixelCalibrationRow
=
pixelCalibrationWS
->
getFirstRow
();
int
calibrationIndex
=
0
;
do
{
double
value
=
(
groupedCalibrationRow
.
Double
(
1
)
/
calibrationWS
->
spectrumInfo
().
diffractometerConstants
(
calibrationWS
->
getIndicesFromDetectorIDs
(
{
pixelCalibrationRow
.
Int
(
0
)})[
0
])[
Kernel
::
UnitParams
::
difc
])
*
pixelCalibrationRow
.
Double
(
1
);
Mantid
::
API
::
TableRow
newRow
=
outputWorkspace
->
appendRow
();
newRow
<<
pixelCalibrationRow
.
Int
(
0
)
<<
value
;
++
calibrationIndex
;
}
while
(
groupedCalibrationRow
.
next
()
&&
pixelCalibrationRow
.
next
());
setProperty
(
"OutputWorkspace"
,
outputWorkspace
);
}
}
// namespace Algorithms
...
...
Framework/Algorithms/test/CombineDiffCalTest.h
View file @
bc302d25
...
...
@@ -8,15 +8,27 @@
#include
<cxxtest/TestSuite.h>
#include
"MantidAPI/ITableWorkspace.h"
#include
"MantidAPI/AnalysisDataService.h"
#include
"MantidAPI/FrameworkManager.h"
#include
"MantidAPI/TableRow.h"
#include
"MantidAlgorithms/CombineDiffCal.h"
#include
"MantidAlgorithms/CreateSampleWorkspace.h"
#include
"MantidDataObjects/TableWorkspace.h"
#include
"MantidDataObjects/Workspace2D.h"
#include
"MantidAlgorithms/CreateSampleWorkspace.h"
#include
"MantidDataHandling/ApplyDiffCal.h"
#include
"MantidDataHandling/GroupDetectors2.h"
using
namespace
Mantid
;
using
namespace
Mantid
::
DataObjects
;
using
namespace
Mantid
::
API
;
using
namespace
Mantid
::
DataHandling
;
using
Mantid
::
Algorithms
::
CombineDiffCal
;
using
Mantid
::
A
PI
::
ITab
leWorkspace
_sptr
;
using
Mantid
::
A
lgorithms
::
CreateSamp
leWorkspace
;
using
Mantid
::
API
::
TableRow
;
using
Mantid
::
DataObjects
::
TableWorkspace
;
using
Mantid
::
DataObjects
::
TableWorkspace_sptr
;
class
CombineDiffCalTest
:
public
CxxTest
::
TestSuite
{
public:
...
...
@@ -25,26 +37,117 @@ public:
static
CombineDiffCalTest
*
createSuite
()
{
return
new
CombineDiffCalTest
();
}
static
void
destroySuite
(
CombineDiffCalTest
*
suite
)
{
delete
suite
;
}
MatrixWorkspace_sptr
create_grouped_workspace
()
{
// CreateSampleWorkspace(OutputWorkspace=name,
// XUnit="dSpacing", NumBanks=1) gives 100 spectra with differenct locations
CombineDiffCalTest
()
{
FrameworkManager
::
Instance
();
}
DataObjects
::
TableWorkspace_sptr
createPixelCalibrationTable
()
{
// create table with correct column names
DataObjects
::
TableWorkspace_sptr
table
=
std
::
make_shared
<
DataObjects
::
TableWorkspace
>
();
table
->
addColumn
(
"int"
,
"detid"
);
table
->
addColumn
(
"double"
,
"difc"
);
table
->
addColumn
(
"double"
,
"difa"
);
table
->
addColumn
(
"double"
,
"tzero"
);
// fill the values
// new_row << entry.detector_id << entry.difc << entry.difa << entry.tzero;
TableRow
newRow
=
table
->
appendRow
();
newRow
<<
100
<<
1000.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
101
<<
1001.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
102
<<
1099.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
103
<<
1101.0
<<
0.0
<<
0.0
;
return
table
;
}
I
TableWorkspace_sptr
create
_diffcal_t
able
()
{
DataObjects
::
TableWorkspace_sptr
create
GroupedCalibrationT
able
()
{
// create table with correct column names
I
TableWorkspace_sptr
table
=
std
::
make_shared
<
TableWorkspace
>
();
DataObjects
::
TableWorkspace_sptr
table
=
std
::
make_shared
<
DataObjects
::
TableWorkspace
>
();
table
->
addColumn
(
"int"
,
"detid"
);
table
->
addColumn
(
"double"
,
"difc"
);
table
->
addColumn
(
"double"
,
"difa"
);
table
->
addColumn
(
"double"
,
"tzero"
);
// fill the values
TableRow
new_row
=
table
->
appendRow
();
// new_row << entry.detector_id << entry.difc << entry.difa << entry.tzero;
TableRow
newRow
=
table
->
appendRow
();
newRow
<<
100
<<
1000.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
101
<<
1001.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
102
<<
1110.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
103
<<
1110.0
<<
0.0
<<
0.0
;
return
table
;
}
DataObjects
::
TableWorkspace_sptr
createCalibrationTableArgs
()
{
// create table with correct column names
DataObjects
::
TableWorkspace_sptr
table
=
std
::
make_shared
<
DataObjects
::
TableWorkspace
>
();
table
->
addColumn
(
"int"
,
"detid"
);
table
->
addColumn
(
"double"
,
"difc"
);
table
->
addColumn
(
"double"
,
"difa"
);
table
->
addColumn
(
"double"
,
"tzero"
);
// fill the values
// new_row << entry.detector_id << entry.difc << entry.difa << entry.tzero;
TableRow
newRow
=
table
->
appendRow
();
newRow
<<
100
<<
1000.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
101
<<
1000.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
102
<<
1100.0
<<
0.0
<<
0.0
;
newRow
=
table
->
appendRow
();
newRow
<<
103
<<
1100.0
<<
0.0
<<
0.0
;
return
table
;
}
MatrixWorkspace_sptr
createCalibrationWorkspace
()
{
CreateSampleWorkspace
createSampleWorkspaceAlgo
;
createSampleWorkspaceAlgo
.
setChild
(
true
);
createSampleWorkspaceAlgo
.
initialize
();
createSampleWorkspaceAlgo
.
setPropertyValue
(
"OutputWorkspace"
,
"outWSName"
);
createSampleWorkspaceAlgo
.
execute
();
MatrixWorkspace_sptr
wipWS
=
createSampleWorkspaceAlgo
.
getProperty
(
"OutputWorkspace"
);
GroupDetectors2
groupDetectorsAlgo
;
groupDetectorsAlgo
.
setChild
(
true
);
groupDetectorsAlgo
.
initialize
();
groupDetectorsAlgo
.
setProperty
(
"InputWorkspace"
,
wipWS
);
groupDetectorsAlgo
.
setProperty
(
"GroupingPattern"
,
"0+1,2+3"
);
groupDetectorsAlgo
.
setPropertyValue
(
"OutputWorkspace"
,
"outWSName"
);
groupDetectorsAlgo
.
execute
();
wipWS
=
groupDetectorsAlgo
.
getProperty
(
"OutputWorkspace"
);
const
auto
calibrationArgsTable
=
createCalibrationTableArgs
();
std
::
string
testWorkspaceName
=
"TestWorkspace"
;
AnalysisDataService
::
Instance
().
add
(
testWorkspaceName
,
wipWS
);
const
auto
outWS
=
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
testWorkspaceName
);
ApplyDiffCal
applyDiffCalAlgo
;
applyDiffCalAlgo
.
setChild
(
true
);
applyDiffCalAlgo
.
initialize
();
applyDiffCalAlgo
.
setProperty
(
"InstrumentWorkspace"
,
testWorkspaceName
);
applyDiffCalAlgo
.
setProperty
(
"CalibrationWorkspace"
,
calibrationArgsTable
);
applyDiffCalAlgo
.
execute
();
return
outWS
;
}
void
test_init
()
{
CombineDiffCal
alg
;
TS_ASSERT_THROWS_NOTHING
(
alg
.
initialize
())
...
...
@@ -60,31 +163,38 @@ public:
// grouped with arb!=group
// test input
auto
difcal_table_pixel
=
create_diffcal_table
();
auto
difcal_table_group
=
create_diffcal_table
();
// TODO create calibration data
// fake data to simulate the output of cross correlate PixelCalibration
const
auto
difCalPixelCalibration
=
createPixelCalibrationTable
();
// fake data to simulate the output of PDCalibration GroupedCalibration
const
auto
difCalGroupedCalibration
=
createGroupedCalibrationTable
();
// fake data to simulate CalibrationWorkspace
const
auto
diffCalCalibrationWs
=
createCalibrationWorkspace
();
// set up algorithm
CombineDiffCal
alg
;
alg
.
setChild
(
true
);
// Don't put output in ADS by default
TS_ASSERT_THROWS_NOTHING
(
alg
.
initialize
());
TS_ASSERT
(
alg
.
isInitialized
());
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"PixelCalibration"
,
dif
c
al
_table_pixel
));
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"GroupedCalibration"
,
dif
c
al
_table_group
));
// TODO
TS_ASSERT_THROWS_NOTHING(
alg.setProperty("CalibrationWorkspace", dif
cal_table_pixel)
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"PixelCalibration"
,
dif
C
al
PixelCalibration
));
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"GroupedCalibration"
,
dif
C
al
GroupedCalibration
));
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"CalibrationWorkspace"
,
dif
fCalCalibrationWs
)
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
setPropertyValue
(
"OutputWorkspace"
,
"_unused_for_child"
));
// run the algorithm
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
(););
TS_ASSERT
(
alg
.
isExecuted
());
/*
// Retrieve the workspace from the algorithm. The type here will probably need to change. It should
// be the type using in declareProperty for the "OutputWorkspace" type.
// We can't use auto as it's an implicit conversion.
Workspace_sptr outputWS = alg.getProperty("OutputWorkspace");
TS_ASSERT(outputWS);
TS_FAIL("TODO: Check the results and remove this line");
*/
DataObjects
::
TableWorkspace_sptr
output
=
alg
.
getProperty
(
"OutputWorkspace"
);
TS_ASSERT
(
output
);
auto
difc
=
output
->
getColumn
(
"difc"
);
TS_ASSERT
(
difc
);
TS_ASSERT_EQUALS
(
difc
->
toDouble
(
0
),
(
1000.
/
1000.
)
*
1000.
);
TS_ASSERT_EQUALS
(
difc
->
toDouble
(
1
),
(
1001.
/
1000.
)
*
1001.
);
TS_ASSERT_EQUALS
(
difc
->
toDouble
(
2
),
(
1110.
/
1100.
)
*
1099.
);
TS_ASSERT_EQUALS
(
difc
->
toDouble
(
3
),
(
1110.
/
1100.
)
*
1101.
);
}
};
docs/source/release/v6.2.0/diffraction.rst
View file @
bc302d25
...
...
@@ -13,6 +13,7 @@ Powder Diffraction
------------------
New features
############
- New algorithm :ref:`CombineDiffCal <algm-CombineDiffCal>` to calibrate groups of pixels after cross correlation so that diffraction peaks can be adjusted to the correct positions
Improvements
############
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment