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
391a7332
Commit
391a7332
authored
7 years ago
by
Zhou, Wenduo
Browse files
Options
Downloads
Patches
Plain Diff
Refs #20796. Refactored exec().
parent
9b8e990e
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/inc/MantidAlgorithms/FindPeakBackground.h
+10
-1
10 additions, 1 deletion
...work/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h
Framework/Algorithms/src/FindPeakBackground.cpp
+121
-28
121 additions, 28 deletions
Framework/Algorithms/src/FindPeakBackground.cpp
with
131 additions
and
29 deletions
Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h
+
10
−
1
View file @
391a7332
...
...
@@ -74,7 +74,9 @@ private:
/// create output workspace
void
createOutputWorkspaces
();
void
findStartStopIndex
(
size_t
&
istart
,
size_t
&
istop
);
/// main method to find peak background
int
findBackground
(
std
::
vector
<
size_t
>
&
peak_min_max_indexes
,
std
::
vector
<
double
>
&
bkgd3
);
/// set histogram data to find background
void
setHistogram
(
const
HistogramData
::
Histogram
&
histogram
);
...
...
@@ -88,12 +90,19 @@ private:
/// set fit window
void
setFitWindow
(
const
std
::
vector
<
double
>
&
window
);
/// add result to output workpsace
void
addResultToOutput
(
const
int
&
goodfit
,
const
std
::
vector
<
size_t
>
&
peakindexes
,
const
std
::
vector
<
double
>
&
bkgdparams
);
/// histogram data to find peak background
boost
::
shared_ptr
<
const
HistogramData
::
Histogram
>
m_histogram
;
// HistogramData::Histogram& m_histogram;
/// fit window
std
::
vector
<
double
>
m_vecFitWindows
;
size_t
m_iStartX
;
/// l0 in original code
size_t
m_iStopX
;
/// n in original code
/// background order: 0 for flat, 1 for linear, 2 for quadratic
size_t
m_backgroundOrder
;
/// constant sigma
...
...
This diff is collapsed.
Click to expand it.
Framework/Algorithms/src/FindPeakBackground.cpp
+
121
−
28
View file @
391a7332
...
...
@@ -71,30 +71,85 @@ void FindPeakBackground::exec() {
// Get input and validate
processInputProperties
();
auto
&
inpX
=
m_histogram
->
x
();
auto
&
inpY
=
m_histogram
->
y
();
size_t
sizex
=
inpX
.
size
();
// inpWS->x(inpwsindex).size();
size_t
sizey
=
inpY
.
size
();
// inpWS->y(inpwsindex).size();
// determine the fit window with their index in X (or Y)
size_t
n
=
sizey
;
size_t
l0
=
0
;
if
(
m_vecFitWindows
.
size
()
>
1
)
{
Mantid
::
Algorithms
::
FindPeaks
fp
;
l0
=
fp
.
getIndex
(
inpX
,
m_vecFitWindows
[
0
]);
n
=
fp
.
getIndex
(
inpX
,
m_vecFitWindows
[
1
]);
if
(
n
<
sizey
)
n
++
;
}
// m_vecFitWindows won't be used again form this point till end.
//
auto &inpX = m_histogram->x();
//
auto &inpY = m_histogram->y();
//
size_t sizex = inpX.size(); // inpWS->x(inpwsindex).size();
//
size_t sizey = inpY.size(); // inpWS->y(inpwsindex).size();
//
//
determine the fit window with their index in X (or Y)
//
size_t n = sizey;
//
size_t l0 = 0;
//
if (m_vecFitWindows.size() > 1) {
//
Mantid::Algorithms::FindPeaks fp;
//
l0 = fp.getIndex(inpX, m_vecFitWindows[0]);
//
n = fp.getIndex(inpX, m_vecFitWindows[1]);
//
if (n < sizey)
//
n++;
//
}
//
//
m_vecFitWindows won't be used again form this point till end.
// Set up output table workspace
createOutputWorkspaces
();
//
3. Get Y values
//
set progress 10%
Progress
prog
(
this
,
0.0
,
1.0
,
1
);
// Find background
std
::
vector
<
size_t
>
peakindexes
;
std
::
vector
<
double
>
bkgdparams
;
int
goodfit
=
findBackground
(
peakindexes
,
bkgdparams
);
// add to output workspace
addResultToOutput
(
goodfit
,
peakindexes
,
bkgdparams
);
prog
.
report
();
// 4. Set the output
setProperty
(
"OutputWorkspace"
,
m_outPeakTableWS
);
}
//----------------------------------------------------------------------------------------------
/**
* @brief FindPeakBackground::addResultToOutput
* @param goodfit
* @param peakindexes
* @param bkgdparams
*/
void
FindPeakBackground
::
addResultToOutput
(
const
int
&
goodfit
,
const
std
::
vector
<
size_t
>
&
peakindexes
,
const
std
::
vector
<
double
>
&
bkgdparams
)
{
if
(
goodfit
>
0
)
{
int
min_peak
=
static_cast
<
int
>
(
peakindexes
[
0
]);
int
max_peak
=
static_cast
<
int
>
(
peakindexes
[
1
]);
double
a0
=
bkgdparams
[
0
];
double
a1
=
bkgdparams
[
1
];
double
a2
=
bkgdparams
[
2
];
API
::
TableRow
t
=
m_outPeakTableWS
->
getRow
(
0
);
t
<<
static_cast
<
int
>
(
m_inputWSIndex
)
<<
min_peak
<<
max_peak
<<
a0
<<
a1
<<
a2
<<
goodfit
;
}
return
;
}
//----------------------------------------------------------------------------------------------
/** Main method to process find peak background
* Note: all inputs shall be set up by this method
* @brief FindPeakBackground::findBackground
* @param peak_min_max_indexes
* @param bkgd3
* @return integer as good fit or not!
*/
int
FindPeakBackground
::
findBackground
(
std
::
vector
<
size_t
>
&
peak_min_max_indexes
,
std
::
vector
<
double
>
&
bkgd3
)
{
// get something from previously set up class variable
auto
&
inpX
=
m_histogram
->
x
();
auto
&
inpY
=
m_histogram
->
y
();
size_t
l0
=
m_iStartX
;
size_t
n
=
m_iStopX
;
int
goodfit
(
0
);
double
Ymean
,
Yvariance
,
Ysigma
;
MantidVec
maskedY
;
auto
in
=
std
::
min_element
(
inpY
.
cbegin
(),
inpY
.
cend
());
...
...
@@ -162,10 +217,10 @@ void FindPeakBackground::exec() {
if
(
inpY
[
l
+
l0
]
>
peaks
[
ipeak
].
maxY
)
peaks
[
ipeak
].
maxY
=
inpY
[
l
+
l0
];
}
}
}
// END-FOR (l)
size_t
min_peak
,
max_peak
;
double
a0
=
0.
,
a1
=
0.
,
a2
=
0.
;
int
goodfit
;
if
(
!
peaks
.
empty
())
{
g_log
.
debug
()
<<
"Peaks' size = "
<<
peaks
.
size
()
<<
" -> esitmate background.
\n
"
;
...
...
@@ -186,20 +241,28 @@ void FindPeakBackground::exec() {
goodfit
=
2
;
}
estimateBackground
(
inpX
,
inpY
,
l0
,
n
,
min_peak
,
max_peak
,
(
!
peaks
.
empty
()),
a0
,
a1
,
a2
);
// Add a new row
API
::
TableRow
t
=
m_outPeakTableWS
->
getRow
(
0
);
t
<<
static_cast
<
int
>
(
m_inputWSIndex
)
<<
static_cast
<
int
>
(
min_peak
)
<<
static_cast
<
int
>
(
max_peak
)
<<
a0
<<
a1
<<
a2
<<
goodfit
;
}
prog
.
report
();
// API::TableRow t = m_outPeakTableWS->getRow(0);
// t << static_cast<int>(m_inputWSIndex) << static_cast<int>(min_peak)
// << static_cast<int>(max_peak) << a0 << a1 << a2 << goodfit;
// 4. Set the output
setProperty
(
"OutputWorkspace"
,
m_outPeakTableWS
);
// set up good fit result
peak_min_max_indexes
.
resize
(
2
);
peak_min_max_indexes
[
0
]
=
min_peak
;
peak_min_max_indexes
[
1
]
=
max_peak
;
bkgd3
.
resize
(
3
);
bkgd3
[
0
]
=
a0
;
bkgd3
[
1
]
=
a1
;
bkgd3
[
2
]
=
a2
;
}
// END-IF: if (n - l0 > 5)
return
goodfit
;
}
//----------------------------------------------------------------------------------------------
...
...
@@ -444,6 +507,10 @@ void FindPeakBackground::setBackgroundOrder(size_t order) {
* @param fitwindow
*/
void
FindPeakBackground
::
setFitWindow
(
const
std
::
vector
<
double
>
&
fitwindow
)
{
size_t
l0
=
0
;
size_t
n
=
m_histogram
->
y
().
size
();
// validate input
if
(
m_vecFitWindows
.
size
()
==
0
)
{
m_vecFitWindows
.
resize
(
2
);
...
...
@@ -453,11 +520,37 @@ void FindPeakBackground::setFitWindow(const std::vector<double> &fitwindow) {
m_vecFitWindows
[
0
]
>=
m_vecFitWindows
[
1
])
{
throw
std
::
invalid_argument
(
"Fit window has either wrong item number or "
"window value is not in ascending order."
);
}
else
{
Mantid
::
Algorithms
::
FindPeaks
fp
;
l0
=
fp
.
getIndex
(
m_histogram
->
x
(),
m_vecFitWindows
[
0
]);
n
=
fp
.
getIndex
(
m_histogram
->
x
(),
m_vecFitWindows
[
1
]);
if
(
n
<
m_histogram
->
y
().
size
())
n
++
;
}
// m_vecFitWindows.resize(2);
// copy the input to class variable
m_vecFitWindows
=
fitwindow
;
m_iStartX
=
l0
;
m_iStopX
=
n
;
// ---- from here .. all from original code
// auto &inpX = m_histogram->x();
// auto &inpY = m_histogram->y();
// size_t sizex = inpX.size(); // inpWS->x(inpwsindex).size();
// size_t sizey = inpY.size(); // inpWS->y(inpwsindex).size();
// determine the fit window with their index in X (or Y)
// size_t n = sizey;
// size_t l0 = 0;
// if (m_vecFitWindows.size() > 1) {
// Mantid::Algorithms::FindPeaks fp;
// l0 = fp.getIndex(inpX, m_vecFitWindows[0]);
// n = fp.getIndex(inpX, m_vecFitWindows[1]);
// if (n < sizey)
// n++;
// }
// m_vecFitWindows won't be used again form this point till end.
return
;
}
...
...
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