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
20353933
Commit
20353933
authored
10 years ago
by
Michael Wedel
Browse files
Options
Downloads
Patches
Plain Diff
Refs #11104. Adding general test for IPeakFunction::intensity
parent
4181b1f3
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
Code/Mantid/Framework/CurveFitting/CMakeLists.txt
+1
-0
1 addition, 0 deletions
Code/Mantid/Framework/CurveFitting/CMakeLists.txt
Code/Mantid/Framework/CurveFitting/test/IPeakFunctionIntensityTest.h
+152
-0
152 additions, 0 deletions
.../Framework/CurveFitting/test/IPeakFunctionIntensityTest.h
with
153 additions
and
0 deletions
Code/Mantid/Framework/CurveFitting/CMakeLists.txt
+
1
−
0
View file @
20353933
...
...
@@ -257,6 +257,7 @@ set ( TEST_FILES
GaussianTest.h
GramCharlierComptonProfileTest.h
IkedaCarpenterPVTest.h
IPeakFunctionIntensityTest.h
LeBailFitTest.h
LeBailFunctionTest.h
LeastSquaresTest.h
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/CurveFitting/test/IPeakFunctionIntensityTest.h
0 → 100644
+
152
−
0
View file @
20353933
#ifndef IPEAKFUNCTIONINTENSITYTEST_H
#define IPEAKFUNCTIONINTENSITYTEST_H
#include
<cxxtest/TestSuite.h>
#include
"MantidAPI/FrameworkManager.h"
#include
"MantidAPI/FunctionFactory.h"
#include
"MantidAPI/IPeakFunction.h"
#include
<boost/lexical_cast.hpp>
using
namespace
Mantid
::
API
;
#define DBL2STR(x) boost::lexical_cast<std::string>(x)
struct
ParameterSet
{
ParameterSet
(
double
c
,
double
h
,
double
f
)
:
center
(
c
),
height
(
h
),
fwhm
(
f
)
{}
double
center
;
double
height
;
double
fwhm
;
};
class
IPeakFunctionIntensityTest
:
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
IPeakFunctionIntensityTest
*
createSuite
()
{
return
new
IPeakFunctionIntensityTest
();
}
static
void
destroySuite
(
IPeakFunctionIntensityTest
*
suite
)
{
delete
suite
;
}
IPeakFunctionIntensityTest
()
:
m_blackList
()
{
FrameworkManager
::
Instance
();
m_blackList
.
insert
(
"BackToBackExponential"
);
m_blackList
.
insert
(
"DeltaFunction"
);
m_blackList
.
insert
(
"ElasticDiffRotDiscreteCircle"
);
m_blackList
.
insert
(
"ElasticDiffSphere"
);
m_peakFunctions
=
getAllPeakFunctions
(
m_blackList
);
m_parameterSets
=
getParameterSets
();
}
/* This test sets all peak function parameters (center, fwhm, height)
* to the values supplied in the first ParameterSet contained in
* m_parameterSets.
*
* Then it retrieves the intensities of the peak functions and stores them.
* Each time new parameters are set, the ratio of the height parameter to
* the previous step is compared to the intensity ratio - they should be
* the same.
*/
void
testAllFunctions
()
{
initializePeakFunctions
(
m_peakFunctions
,
m_parameterSets
[
0
]);
std
::
vector
<
double
>
initialIntensities
=
getIntensities
(
m_peakFunctions
);
for
(
size_t
i
=
1
;
i
<
m_parameterSets
.
size
();
++
i
)
{
double
oldHeight
=
m_parameterSets
[
i
-
1
].
height
;
double
newHeight
=
m_parameterSets
[
i
].
height
;
double
heightRatio
=
newHeight
/
oldHeight
;
initializePeakFunctions
(
m_peakFunctions
,
m_parameterSets
[
i
]);
std
::
vector
<
double
>
newIntensities
=
getIntensities
(
m_peakFunctions
);
for
(
size_t
j
=
0
;
j
<
initialIntensities
.
size
();
++
j
)
{
double
oldIntensity
=
initialIntensities
[
j
];
double
newIntensity
=
newIntensities
[
j
];
double
intensityRatio
=
newIntensity
/
oldIntensity
;
TSM_ASSERT_DELTA
(
"ITERATION "
+
DBL2STR
(
i
)
+
", "
+
m_peakFunctions
[
j
]
->
name
()
+
": Height was increased from "
+
DBL2STR
(
oldHeight
)
+
" to "
+
DBL2STR
(
newHeight
)
+
" (ratio "
+
DBL2STR
(
heightRatio
)
+
"), but intensity changed from "
+
DBL2STR
(
oldIntensity
)
+
" to "
+
DBL2STR
(
newIntensity
)
+
" (ratio "
+
DBL2STR
(
intensityRatio
)
+
")."
,
intensityRatio
,
heightRatio
,
1e-10
);
}
initialIntensities
=
newIntensities
;
}
}
private
:
std
::
vector
<
IPeakFunction_sptr
>
getAllPeakFunctions
(
const
std
::
set
<
std
::
string
>
&
blackList
)
const
{
std
::
vector
<
IPeakFunction_sptr
>
peakFunctions
;
std
::
vector
<
std
::
string
>
registeredFunctions
=
FunctionFactory
::
Instance
().
getFunctionNames
<
IPeakFunction
>
();
for
(
auto
it
=
registeredFunctions
.
begin
();
it
!=
registeredFunctions
.
end
();
++
it
)
{
if
(
blackList
.
count
(
*
it
)
==
0
)
{
IPeakFunction_sptr
peakFunction
=
boost
::
dynamic_pointer_cast
<
IPeakFunction
>
(
FunctionFactory
::
Instance
().
createFunction
(
*
it
));
if
(
peakFunction
)
{
peakFunctions
.
push_back
(
peakFunction
);
}
}
}
return
peakFunctions
;
}
void
initializePeakFunctions
(
const
std
::
vector
<
IPeakFunction_sptr
>
&
peaks
,
const
ParameterSet
&
parameters
)
const
{
for
(
auto
it
=
peaks
.
begin
();
it
!=
peaks
.
end
();
++
it
)
{
(
*
it
)
->
setCentre
(
parameters
.
center
);
// for Ikeda-Carpenter it's not allowed to set Fwhm
try
{
(
*
it
)
->
setFwhm
(
parameters
.
fwhm
);
}
catch
(
std
::
invalid_argument
)
{
}
(
*
it
)
->
setHeight
(
parameters
.
height
);
}
}
std
::
vector
<
ParameterSet
>
getParameterSets
()
const
{
std
::
vector
<
ParameterSet
>
parameterSets
;
parameterSets
.
push_back
(
ParameterSet
(
0.0
,
4.34
,
0.25
));
parameterSets
.
push_back
(
ParameterSet
(
0.0
,
5.34
,
0.25
));
parameterSets
.
push_back
(
ParameterSet
(
0.0
,
6.34
,
0.25
));
parameterSets
.
push_back
(
ParameterSet
(
0.0
,
7.34
,
0.25
));
return
parameterSets
;
}
std
::
vector
<
double
>
getIntensities
(
const
std
::
vector
<
IPeakFunction_sptr
>
&
peaks
)
const
{
std
::
vector
<
double
>
intensities
;
for
(
auto
it
=
peaks
.
begin
();
it
!=
peaks
.
end
();
++
it
)
{
intensities
.
push_back
((
*
it
)
->
intensity
());
}
return
intensities
;
}
std
::
vector
<
IPeakFunction_sptr
>
m_peakFunctions
;
std
::
vector
<
ParameterSet
>
m_parameterSets
;
std
::
set
<
std
::
string
>
m_blackList
;
};
#endif // IPEAKFUNCTIONINTENSITYTEST_H
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