Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
6e018cb3
Commit
6e018cb3
authored
7 years ago
by
WHITFIELDRE email
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #20784 from mantidproject/20776_phaseQuadTest
Fix PhaseQuad test
parents
4cdccf4c
890002fe
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Framework/Algorithms/src/PhaseQuadMuon.cpp
+14
-21
14 additions, 21 deletions
Framework/Algorithms/src/PhaseQuadMuon.cpp
Framework/Algorithms/test/PhaseQuadMuonTest.h
+70
-57
70 additions, 57 deletions
Framework/Algorithms/test/PhaseQuadMuonTest.h
with
84 additions
and
78 deletions
Framework/Algorithms/src/PhaseQuadMuon.cpp
+
14
−
21
View file @
6e018cb3
...
...
@@ -7,12 +7,12 @@
#include
"MantidKernel/Unit.h"
namespace
{
const
std
::
vector
<
std
::
string
>
phaseNames
=
{
"phase"
,
"phi"
};
const
std
::
vector
<
std
::
string
>
asymmNames
=
{
"asymmetry"
,
"asymm"
,
"asym"
};
const
std
::
array
<
std
::
string
,
2
>
phaseNames
=
{
{
"phase"
,
"phi"
}
}
;
const
std
::
array
<
std
::
string
,
3
>
asymmNames
=
{
{
"asymmetry"
,
"asymm"
,
"asym"
}
}
;
int
findName
(
const
std
::
vector
<
std
::
string
>
&
patterns
,
const
std
::
vector
<
std
::
string
>
&
names
)
{
for
(
std
::
string
pattern
:
patterns
)
{
template
<
typename
T1
,
typename
T2
>
int
findName
(
const
T1
&
patterns
,
const
T2
&
names
)
{
for
(
const
std
::
string
&
pattern
:
patterns
)
{
auto
it
=
std
::
find_if
(
names
.
begin
(),
names
.
end
(),
[
pattern
](
const
std
::
string
&
s
)
{
if
(
s
==
pattern
)
{
...
...
@@ -116,26 +116,20 @@ std::map<std::string, std::string> PhaseQuadMuon::validateInputs() {
result
[
"PhaseTable"
]
=
"PhaseTable must have three columns"
;
}
auto
names
=
tabWS
->
getColumnNames
();
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
std
::
transform
(
names
[
j
].
begin
(),
names
[
j
].
end
(),
names
[
j
].
begin
(),
::
tolower
);
for
(
auto
&
name
:
names
)
{
std
::
transform
(
name
.
begin
(),
name
.
end
(),
name
.
begin
(),
::
tolower
);
}
int
phaseCount
=
0
;
int
asymmetryCount
=
0
;
for
(
std
::
string
name
:
names
)
{
for
(
std
::
string
goodName
:
phaseNames
)
{
for
(
const
std
::
string
&
name
:
names
)
{
for
(
const
std
::
string
&
goodName
:
phaseNames
)
{
if
(
name
==
goodName
)
{
phaseCount
+=
1
;
}
}
}
for
(
std
::
string
name
:
names
)
{
for
(
std
::
string
goodName
:
asymmNames
)
{
for
(
const
std
::
string
&
goodName
:
asymmNames
)
{
if
(
name
==
goodName
)
{
if
(
name
==
goodName
)
{
asymmetryCount
+=
1
;
}
asymmetryCount
+=
1
;
}
}
}
...
...
@@ -230,9 +224,8 @@ PhaseQuadMuon::squash(const API::MatrixWorkspace_sptr &ws,
}
auto
names
=
phase
->
getColumnNames
();
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
std
::
transform
(
names
[
j
].
begin
(),
names
[
j
].
end
(),
names
[
j
].
begin
(),
::
tolower
);
for
(
auto
&
name
:
names
)
{
std
::
transform
(
name
.
begin
(),
name
.
end
(),
name
.
begin
(),
::
tolower
);
}
auto
phaseIndex
=
findName
(
phaseNames
,
names
);
auto
asymmetryIndex
=
findName
(
asymmNames
,
names
);
...
...
@@ -295,7 +288,7 @@ PhaseQuadMuon::squash(const API::MatrixWorkspace_sptr &ws,
auto
&
realE
=
ows
->
mutableE
(
0
);
auto
&
imagE
=
ows
->
mutableE
(
1
);
const
auto
&
xPointData
=
ws
->
histogram
(
0
).
points
();
const
auto
xPointData
=
ws
->
histogram
(
0
).
points
();
// First X value
const
double
X0
=
xPointData
.
front
();
...
...
This diff is collapsed.
Click to expand it.
Framework/Algorithms/test/PhaseQuadMuonTest.h
+
70
−
57
View file @
6e018cb3
...
...
@@ -17,51 +17,54 @@ using namespace Mantid::API;
namespace
{
void
populatePhaseTable
(
ITableWorkspace_sptr
phaseTable
,
std
::
vector
<
std
::
string
>
names
)
{
std
::
vector
<
std
::
string
>
names
,
bool
swap
=
false
)
{
phaseTable
->
addColumn
(
"int"
,
names
[
0
]);
phaseTable
->
addColumn
(
"double"
,
names
[
1
]);
phaseTable
->
addColumn
(
"double"
,
names
[
2
]);
double
asym
(
1.
),
phase
(
2.
);
if
(
swap
)
{
std
::
swap
(
asym
,
phase
);
}
for
(
int
i
=
0
;
i
<
16
;
i
++
)
{
TableRow
phaseRow1
=
phaseTable
->
appendRow
();
phaseRow1
<<
i
<<
1.
<<
2.
*
M_PI
*
double
(
i
)
/
16.
;
phaseRow1
<<
i
<<
asym
<<
phase
;
TableRow
phaseRow2
=
phaseTable
->
appendRow
();
phaseRow2
<<
i
<<
1.
<<
2.
*
M_PI
*
double
(
i
)
/
16.
;
phaseRow2
<<
i
<<
asym
<<
phase
;
}
}
void
populatePhaseTable
(
ITableWorkspace_sptr
phaseTable
)
{
populatePhaseTable
(
phaseTable
,
{
"DetectorID"
,
"Asymmetry"
,
"Phase"
});
}
IAlgorithm_sptr
setupAlg
(
MatrixWorkspace_sptr
inputWs
,
bool
isChildAlg
,
IAlgorithm_sptr
setupAlg
(
MatrixWorkspace_sptr
m_loadedData
,
bool
isChildAlg
,
ITableWorkspace_sptr
phaseTable
)
{
// Set up PhaseQuad
IAlgorithm_sptr
phaseQuad
=
AlgorithmManager
::
Instance
().
create
(
"PhaseQuad"
);
phaseQuad
->
setChild
(
isChildAlg
);
phaseQuad
->
initialize
();
phaseQuad
->
setProperty
(
"InputWorkspace"
,
inputWs
);
phaseQuad
->
setProperty
(
"InputWorkspace"
,
m_loadedData
);
phaseQuad
->
setProperty
(
"PhaseTable"
,
phaseTable
);
phaseQuad
->
setPropertyValue
(
"OutputWorkspace"
,
"outputWs"
);
return
phaseQuad
;
}
IAlgorithm_sptr
setupAlg
(
MatrixWorkspace_sptr
inputWs
,
bool
isChildAlg
)
{
IAlgorithm_sptr
setupAlg
(
MatrixWorkspace_sptr
m_loadedData
,
bool
isChildAlg
)
{
// Create and populate a detector table
boost
::
shared_ptr
<
ITableWorkspace
>
phaseTable
(
new
Mantid
::
DataObjects
::
TableWorkspace
);
populatePhaseTable
(
phaseTable
);
return
setupAlg
(
inputWs
,
isChildAlg
,
phaseTable
);
return
setupAlg
(
m_loadedData
,
isChildAlg
,
phaseTable
);
}
IAlgorithm_sptr
setupAlg
(
MatrixWorkspace_sptr
inputWs
,
bool
isChildAlg
,
std
::
vector
<
std
::
string
>
names
)
{
IAlgorithm_sptr
setupAlg
(
MatrixWorkspace_sptr
m_loadedData
,
bool
isChildAlg
,
std
::
vector
<
std
::
string
>
names
,
bool
swap
=
false
)
{
// Create and populate a detector table
boost
::
shared_ptr
<
ITableWorkspace
>
phaseTable
(
new
Mantid
::
DataObjects
::
TableWorkspace
);
populatePhaseTable
(
phaseTable
,
names
);
populatePhaseTable
(
phaseTable
,
names
,
swap
);
return
setupAlg
(
inputWs
,
isChildAlg
,
phaseTable
);
return
setupAlg
(
m_loadedData
,
isChildAlg
,
phaseTable
);
}
MatrixWorkspace_sptr
loadMuonDataset
()
{
...
...
@@ -72,14 +75,26 @@ MatrixWorkspace_sptr loadMuonDataset() {
loader
->
setPropertyValue
(
"OutputWorkspace"
,
"outputWs"
);
loader
->
execute
();
Workspace_sptr
temp
=
loader
->
getProperty
(
"OutputWorkspace"
);
MatrixWorkspace_sptr
inputWs
=
MatrixWorkspace_sptr
m_loadedData
=
boost
::
dynamic_pointer_cast
<
MatrixWorkspace
>
(
temp
);
return
inputWs
;
return
m_loadedData
;
}
}
class
PhaseQuadMuonTest
:
public
CxxTest
::
TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static
PhaseQuadMuonTest
*
createSuite
()
{
return
new
PhaseQuadMuonTest
();
}
static
void
destroySuite
(
PhaseQuadMuonTest
*
suite
)
{
delete
suite
;
}
void
setUp
()
override
{
if
(
!
m_loadedData
)
{
m_loadedData
=
loadMuonDataset
();
}
}
void
testTheBasics
()
{
IAlgorithm_sptr
phaseQuad
=
AlgorithmManager
::
Instance
().
create
(
"PhaseQuad"
);
...
...
@@ -90,8 +105,7 @@ public:
}
void
testExecPhaseTable
()
{
MatrixWorkspace_sptr
inputWs
=
loadMuonDataset
();
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
inputWs
,
true
);
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
m_loadedData
,
true
);
TS_ASSERT_THROWS_NOTHING
(
phaseQuad
->
execute
());
TS_ASSERT
(
phaseQuad
->
isExecuted
());
...
...
@@ -101,59 +115,55 @@ public:
TS_ASSERT_EQUALS
(
outputWs
->
getNumberHistograms
(),
2
);
TS_ASSERT_EQUALS
(
outputWs
->
getSpectrum
(
0
).
readX
(),
inputWs
->
getSpectrum
(
0
).
readX
());
// Check outputWs X values
m_loadedData
->
getSpectrum
(
0
).
readX
());
// Check outputWs X values
TS_ASSERT_EQUALS
(
outputWs
->
getSpectrum
(
1
).
readX
(),
inputWs
->
getSpectrum
(
1
).
readX
());
m_loadedData
->
getSpectrum
(
1
).
readX
());
const
auto
specReY
=
outputWs
->
getSpectrum
(
0
).
y
();
const
auto
specReE
=
outputWs
->
getSpectrum
(
0
).
e
();
const
auto
specImY
=
outputWs
->
getSpectrum
(
1
).
y
();
const
auto
specImE
=
outputWs
->
getSpectrum
(
1
).
e
();
// Check real Y values
TS_ASSERT_DELTA
(
specReY
[
0
],
-
0.0531
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
20
],
-
0.0
013
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
50
],
0.0
048
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
0
],
2.1969
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
20
],
0.0
510
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
50
],
-
0.0
525
,
0.0001
);
// Check real E values
TS_ASSERT_DELTA
(
specReE
[
0
],
0.00
16
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
20
],
0.00
25
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
50
],
0.00
29
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
0
],
0.00
24
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
20
],
0.00
41
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
50
],
0.00
47
,
0.0001
);
// Check imaginary Y values
TS_ASSERT_DELTA
(
specImY
[
0
],
-
0.
7
03
0
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
20
],
-
0.00
9
6
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
50
],
0.0
254
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
0
],
-
0.
1
03
5
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
20
],
-
0.00
0
6
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
50
],
0.0
047
,
0.0001
);
// Check imaginary E values
TS_ASSERT_DELTA
(
specImE
[
0
],
0.00
1
2
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
20
],
0.00
27
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
50
],
0.00
31
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
0
],
0.00
0
2
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
20
],
0.00
04
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
50
],
0.00
05
,
0.0001
);
}
void
testNoPhase
()
{
std
::
vector
<
std
::
string
>
names
=
{
"ID"
,
"Asym"
,
"dummy"
};
MatrixWorkspace_sptr
inputWs
=
loadMuonDataset
();
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
inputWs
,
true
,
names
);
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
m_loadedData
,
true
,
names
);
TS_ASSERT_THROWS
(
phaseQuad
->
execute
(),
std
::
runtime_error
);
}
void
testNoAsymm
()
{
std
::
vector
<
std
::
string
>
names
=
{
"ID"
,
"AsYMg"
,
"phase"
};
MatrixWorkspace_sptr
inputWs
=
loadMuonDataset
();
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
inputWs
,
true
,
names
);
MatrixWorkspace_sptr
m_loadedData
=
loadMuonDataset
();
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
m_loadedData
,
true
,
names
);
TS_ASSERT_THROWS
(
phaseQuad
->
execute
(),
std
::
runtime_error
);
}
void
testTwoPhases
()
{
std
::
vector
<
std
::
string
>
names
=
{
"ID"
,
"Phase"
,
"phi"
};
MatrixWorkspace_sptr
inputWs
=
loadMuonDataset
();
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
inputWs
,
true
,
names
);
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
m_loadedData
,
true
,
names
);
TS_ASSERT_THROWS
(
phaseQuad
->
execute
(),
std
::
runtime_error
);
}
void
testTwoAsymm
()
{
std
::
vector
<
std
::
string
>
names
=
{
"ID"
,
"Asym"
,
"Asymm"
};
MatrixWorkspace_sptr
inputWs
=
loadMuonDataset
();
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
inputWs
,
true
,
names
);
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
m_loadedData
,
true
,
names
);
TS_ASSERT_THROWS
(
phaseQuad
->
execute
(),
std
::
runtime_error
);
}
void
testSwapOrder
()
{
std
::
vector
<
std
::
string
>
names
=
{
"ID"
,
"phase"
,
"Asymm"
};
MatrixWorkspace_sptr
inputWs
=
loadMuonDataset
();
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
inputWs
,
true
,
names
);
IAlgorithm_sptr
phaseQuad
=
setupAlg
(
m_loadedData
,
true
,
names
,
true
);
TS_ASSERT_THROWS_NOTHING
(
phaseQuad
->
execute
());
TS_ASSERT
(
phaseQuad
->
isExecuted
());
...
...
@@ -163,32 +173,35 @@ public:
TS_ASSERT_EQUALS
(
outputWs
->
getNumberHistograms
(),
2
);
TS_ASSERT_EQUALS
(
outputWs
->
getSpectrum
(
0
).
readX
(),
inputWs
->
getSpectrum
(
0
).
readX
());
// Check outputWs X values
m_loadedData
->
getSpectrum
(
0
).
readX
());
// Check outputWs X values
TS_ASSERT_EQUALS
(
outputWs
->
getSpectrum
(
1
).
readX
(),
inputWs
->
getSpectrum
(
1
).
readX
());
m_loadedData
->
getSpectrum
(
1
).
readX
());
const
auto
specReY
=
outputWs
->
getSpectrum
(
0
).
y
();
const
auto
specReE
=
outputWs
->
getSpectrum
(
0
).
e
();
const
auto
specImY
=
outputWs
->
getSpectrum
(
1
).
y
();
const
auto
specImE
=
outputWs
->
getSpectrum
(
1
).
e
();
// Check real Y values
TS_ASSERT_DELTA
(
specReY
[
0
],
-
3.9473
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
20
],
-
0.
1183
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
50
],
0.05
04
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
0
],
2.1969
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
20
],
0.
0510
,
0.0001
);
TS_ASSERT_DELTA
(
specReY
[
50
],
-
0.05
25
,
0.0001
);
// Check real E values
TS_ASSERT_DELTA
(
specReE
[
0
],
0.00
5
4
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
20
],
0.00
8
1
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
50
],
0.00
93
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
0
],
0.00
2
4
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
20
],
0.00
4
1
,
0.0001
);
TS_ASSERT_DELTA
(
specReE
[
50
],
0.00
47
,
0.0001
);
// Check imaginary Y values
TS_ASSERT_DELTA
(
specImY
[
0
],
0.
4317
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
20
],
0.00
58
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
50
],
0.00
58
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
0
],
-
0.
1035
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
20
],
-
0.00
06
,
0.0001
);
TS_ASSERT_DELTA
(
specImY
[
50
],
0.00
47
,
0.0001
);
// Check imaginary E values
TS_ASSERT_DELTA
(
specImE
[
0
],
0.00
17
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
20
],
0.00
3
4
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
50
],
0.00
39
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
0
],
0.00
02
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
20
],
0.00
0
4
,
0.0001
);
TS_ASSERT_DELTA
(
specImE
[
50
],
0.00
05
,
0.0001
);
}
// add test for different order
private
:
MatrixWorkspace_sptr
m_loadedData
;
};
class
PhaseQuadMuonTestPerformance
:
public
CxxTest
::
TestSuite
{
...
...
@@ -205,8 +218,8 @@ public:
}
void
setUp
()
override
{
inputWs
=
loadMuonDataset
();
phaseQuad
=
setupAlg
(
inputWs
,
false
);
m_loadedData
=
loadMuonDataset
();
phaseQuad
=
setupAlg
(
m_loadedData
,
false
);
}
void
tearDown
()
override
{
...
...
@@ -216,7 +229,7 @@ public:
void
testPerformanceWs
()
{
phaseQuad
->
execute
();
}
private
:
MatrixWorkspace_sptr
inputWs
;
MatrixWorkspace_sptr
m_loadedData
;
IAlgorithm_sptr
phaseQuad
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment