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
a80ebf45
Commit
a80ebf45
authored
9 years ago
by
Pete Peterson
Browse files
Options
Downloads
Plain Diff
Merge pull request #13990 from mantidproject/13968_Review_RemoveExpDecay
Review RemoveExpDecay
parents
96df753c
cd321aec
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Framework/Algorithms/test/RemoveExpDecayTest.h
+149
-36
149 additions, 36 deletions
Framework/Algorithms/test/RemoveExpDecayTest.h
docs/source/algorithms/RemoveExpDecay-v1.rst
+3
-2
3 additions, 2 deletions
docs/source/algorithms/RemoveExpDecay-v1.rst
with
152 additions
and
38 deletions
Framework/Algorithms/test/RemoveExpDecayTest.h
+
149
−
36
View file @
a80ebf45
...
...
@@ -3,11 +3,11 @@
#include
<cxxtest/TestSuite.h>
#include
"MantidAPI/FrameworkManager.h"
#include
"MantidAlgorithm
s/RemoveExpDecay
.h"
#include
"Mantid
API/
Algorithm
Manager
.h"
#include
"MantidTestHelpers/WorkspaceCreationHelper.h"
using
namespace
Mantid
::
Algorithms
;
using
namespace
Mantid
::
API
;
using
Mantid
::
MantidVec
;
const
std
::
string
outputName
=
"MuonRemoveExpDecay_Output"
;
...
...
@@ -21,52 +21,165 @@ public:
RemoveExpDecayTest
()
{
FrameworkManager
::
Instance
();
}
void
testInit
()
{
Muon
RemoveExpDecay
alg
;
alg
.
initialize
();
TS_ASSERT
(
alg
.
isInitialized
())
IAlgorithm_sptr
alg
=
AlgorithmManager
::
Instance
().
create
(
"
RemoveExpDecay
"
)
;
alg
->
initialize
();
TS_ASSERT
(
alg
->
isInitialized
())
}
void
testExecute
()
{
auto
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
1
,
1
);
MuonRemoveExpDecay
alg
;
TS_ASSERT_THROWS_NOTHING
(
alg
.
initialize
());
TS_ASSERT
(
alg
.
isInitialized
());
alg
.
setChild
(
true
);
alg
.
setProperty
(
"InputWorkspace"
,
ws
);
alg
.
setPropertyValue
(
"OutputWorkspace"
,
outputName
);
alg
.
setPropertyValue
(
"Spectra"
,
"0"
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
());
TS_ASSERT
(
alg
.
isExecuted
())
void
test_Execute
()
{
auto
ws
=
createWorkspace
(
1
,
50
);
IAlgorithm_sptr
alg
=
AlgorithmManager
::
Instance
().
create
(
"RemoveExpDecay"
);
alg
->
initialize
();
alg
->
setChild
(
true
);
alg
->
setProperty
(
"InputWorkspace"
,
ws
);
alg
->
setPropertyValue
(
"OutputWorkspace"
,
outputName
);
TS_ASSERT_THROWS_NOTHING
(
alg
->
execute
());
TS_ASSERT
(
alg
->
isExecuted
());
MatrixWorkspace_sptr
outWS
=
alg
->
getProperty
(
"OutputWorkspace"
);
}
void
testExecuteWhereSepctraNotSet
()
{
auto
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
1
,
1
);
MuonRemoveExpDecay
alg
;
TS_ASSERT_THROWS_NOTHING
(
alg
.
initialize
());
TS_ASSERT
(
alg
.
isInitialized
());
alg
.
setChild
(
true
);
alg
.
setProperty
(
"InputWorkspace"
,
ws
);
alg
.
setPropertyValue
(
"OutputWorkspace"
,
outputName
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
());
TS_ASSERT
(
alg
.
isExecuted
())
void
test_EmptySpectrumList
()
{
auto
ws
=
createWorkspace
(
2
,
50
);
IAlgorithm_sptr
alg
=
AlgorithmManager
::
Instance
().
create
(
"RemoveExpDecay"
);
alg
->
initialize
();
alg
->
setChild
(
true
);
alg
->
setProperty
(
"InputWorkspace"
,
ws
);
alg
->
setPropertyValue
(
"OutputWorkspace"
,
outputName
);
TS_ASSERT_THROWS_NOTHING
(
alg
->
execute
());
TS_ASSERT
(
alg
->
isExecuted
());
MatrixWorkspace_sptr
outWS
=
alg
->
getProperty
(
"OutputWorkspace"
);
// First spectrum
// Test some X values
TS_ASSERT_DELTA
(
outWS
->
readX
(
0
)[
10
],
0.2000
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readX
(
0
)[
19
],
0.3800
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readX
(
0
)[
49
],
0.9800
,
0.0001
);
// Test some Y values
TS_ASSERT_DELTA
(
outWS
->
readY
(
0
)[
10
],
-
0.0992
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readY
(
0
)[
19
],
-
0.0111
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readY
(
0
)[
49
],
-
0.0622
,
0.0001
);
// Test some E values
TS_ASSERT_DELTA
(
outWS
->
readE
(
0
)[
10
],
0.0054
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readE
(
0
)[
19
],
0.0059
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readE
(
0
)[
49
],
0.0077
,
0.0001
);
// Second spectrum
// Test some X values
TS_ASSERT_DELTA
(
outWS
->
readX
(
1
)[
10
],
0.2000
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readX
(
1
)[
19
],
0.3800
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readX
(
1
)[
49
],
0.9800
,
0.0001
);
// Test some Y values
TS_ASSERT_DELTA
(
outWS
->
readY
(
1
)[
10
],
0.0274
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readY
(
1
)[
19
],
-
0.1003
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readY
(
1
)[
49
],
0.0802
,
0.0001
);
// Test some E values
TS_ASSERT_DELTA
(
outWS
->
readE
(
1
)[
10
],
0.0054
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readE
(
1
)[
19
],
0.0059
,
0.0001
);
TS_ASSERT_DELTA
(
outWS
->
readE
(
1
)[
49
],
0.0078
,
0.0001
);
}
void
test_SpectrumList
()
{
auto
ws
=
createWorkspace
(
2
,
50
);
// First, run the algorithm without specifying any spectrum
IAlgorithm_sptr
alg1
=
AlgorithmManager
::
Instance
().
create
(
"RemoveExpDecay"
);
alg1
->
initialize
();
alg1
->
setChild
(
true
);
alg1
->
setProperty
(
"InputWorkspace"
,
ws
);
alg1
->
setPropertyValue
(
"OutputWorkspace"
,
outputName
);
TS_ASSERT_THROWS_NOTHING
(
alg1
->
execute
());
TS_ASSERT
(
alg1
->
isExecuted
());
MatrixWorkspace_sptr
out1
=
alg1
->
getProperty
(
"OutputWorkspace"
);
// Then run the algorithm on the second spectrum only
IAlgorithm_sptr
alg2
=
AlgorithmManager
::
Instance
().
create
(
"RemoveExpDecay"
);
alg2
->
initialize
();
alg2
->
setChild
(
true
);
alg2
->
setProperty
(
"InputWorkspace"
,
ws
);
alg2
->
setPropertyValue
(
"OutputWorkspace"
,
outputName
);
alg2
->
setPropertyValue
(
"Spectra"
,
"1"
);
TS_ASSERT_THROWS_NOTHING
(
alg2
->
execute
());
TS_ASSERT
(
alg2
->
isExecuted
());
MatrixWorkspace_sptr
out2
=
alg2
->
getProperty
(
"OutputWorkspace"
);
// Both output workspaces should have 2 spectra
TS_ASSERT_EQUALS
(
out1
->
getNumberHistograms
(),
ws
->
getNumberHistograms
());
TS_ASSERT_EQUALS
(
out2
->
getNumberHistograms
(),
ws
->
getNumberHistograms
());
// Compare results, they should match for the selected spectrum
TS_ASSERT_EQUALS
(
out1
->
readX
(
1
),
out2
->
readX
(
1
));
TS_ASSERT_EQUALS
(
out1
->
readY
(
1
),
out2
->
readY
(
1
));
TS_ASSERT_EQUALS
(
out1
->
readE
(
1
),
out2
->
readE
(
1
));
// Compare non-selected spectra, the should match the input ones
TS_ASSERT_EQUALS
(
ws
->
readX
(
0
),
out2
->
readX
(
0
));
TS_ASSERT_EQUALS
(
ws
->
readY
(
0
),
out2
->
readY
(
0
));
TS_ASSERT_EQUALS
(
ws
->
readE
(
0
),
out2
->
readE
(
0
));
}
void
test_yUnitLabel
()
{
auto
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
1
,
1
);
MuonRemoveExpDecay
alg
;
alg
.
initialize
();
alg
.
setChild
(
true
);
alg
.
setProperty
(
"InputWorkspace"
,
ws
);
alg
.
setProperty
(
"OutputWorkspace"
,
outputName
);
alg
.
execute
();
auto
ws
=
createWorkspace
(
4
,
50
);
IAlgorithm_sptr
alg
=
AlgorithmManager
::
Instance
().
create
(
"RemoveExpDecay"
);
alg
->
initialize
();
alg
->
setChild
(
true
);
alg
->
setProperty
(
"InputWorkspace"
,
ws
);
alg
->
setPropertyValue
(
"OutputWorkspace"
,
outputName
);
TS_ASSERT_THROWS_NOTHING
(
alg
->
execute
());
TS_ASSERT
(
alg
->
isExecuted
())
MatrixWorkspace_sptr
result
=
alg
.
getProperty
(
"OutputWorkspace"
);
MatrixWorkspace_sptr
result
=
alg
->
getProperty
(
"OutputWorkspace"
);
TS_ASSERT
(
result
);
TS_ASSERT_EQUALS
(
result
->
YUnitLabel
(),
"Asymmetry"
);
}
MatrixWorkspace_sptr
createWorkspace
(
size_t
nspec
,
size_t
maxt
)
{
// Create a fake muon dataset
double
a
=
0.1
;
// Amplitude of the oscillations
double
w
=
25.
;
// Frequency of the oscillations
double
tau
=
2.2
;
// Muon life time
MantidVec
X
;
MantidVec
Y
;
MantidVec
E
;
for
(
size_t
s
=
0
;
s
<
nspec
;
s
++
)
{
for
(
size_t
t
=
0
;
t
<
maxt
;
t
++
)
{
double
x
=
static_cast
<
double
>
(
t
)
/
static_cast
<
double
>
(
maxt
);
double
e
=
exp
(
-
x
/
tau
);
X
.
push_back
(
x
);
Y
.
push_back
(
a
*
sin
(
w
*
x
+
static_cast
<
double
>
(
s
)
*
M_PI
/
static_cast
<
double
>
(
nspec
))
*
e
+
e
);
E
.
push_back
(
0.005
);
}
}
auto
createWS
=
AlgorithmManager
::
Instance
().
create
(
"CreateWorkspace"
);
createWS
->
initialize
();
createWS
->
setChild
(
true
);
createWS
->
setProperty
(
"DataX"
,
X
);
createWS
->
setProperty
(
"DataY"
,
Y
);
createWS
->
setProperty
(
"DataE"
,
E
);
createWS
->
setProperty
(
"NSpec"
,
static_cast
<
int
>
(
nspec
));
createWS
->
setPropertyValue
(
"OutputWorkspace"
,
"ws"
);
createWS
->
execute
();
MatrixWorkspace_sptr
ws
=
createWS
->
getProperty
(
"OutputWorkspace"
);
return
ws
;
}
};
#endif
/*MUONREMOVEEXPDECAYTEST_H_*/
This diff is collapsed.
Click to expand it.
docs/source/algorithms/RemoveExpDecay-v1.rst
+
3
−
2
View file @
a80ebf45
...
...
@@ -9,8 +9,9 @@
Description
-----------
This algorithm removes the exponential time decay from a specified muon
spectra. By default, all the spectra in a workspace will be corrected.
This algorithm removes the exponential time decay from the specified muon
spectra, leaving the rest unchanged. By default, all the spectra
in a workspace will be corrected.
The formula for removing the exponential decay is given by:
...
...
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