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
a32dcb48
Commit
a32dcb48
authored
10 years ago
by
Gigg, Martyn Anthony
Browse files
Options
Downloads
Patches
Plain Diff
Refactor a few more parts in to methods.
Refs #10470
parent
c6ecf32e
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/MDAlgorithms/inc/MantidMDAlgorithms/SXDMDNorm.h
+5
-3
5 additions, 3 deletions
...Framework/MDAlgorithms/inc/MantidMDAlgorithms/SXDMDNorm.h
Code/Mantid/Framework/MDAlgorithms/src/SXDMDNorm.cpp
+118
-93
118 additions, 93 deletions
Code/Mantid/Framework/MDAlgorithms/src/SXDMDNorm.cpp
with
123 additions
and
96 deletions
Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SXDMDNorm.h
+
5
−
3
View file @
a32dcb48
...
@@ -46,11 +46,13 @@ namespace Mantid
...
@@ -46,11 +46,13 @@ namespace Mantid
void
init
();
void
init
();
void
exec
();
void
exec
();
std
::
string
inputEnergyMode
()
const
;
void
initCaches
();
void
initCaches
();
std
::
vector
<
coord_t
>
getValuesFromOtherDimensions
(
bool
&
skipNormalization
)
const
;
std
::
string
inputEnergyMode
(
)
const
;
MDEvents
::
MDHistoWorkspace_sptr
binInputWS
();
MDEvents
::
MDHistoWorkspace_sptr
binInputWS
();
void
createNormalizationWS
(
const
MDEvents
::
MDHistoWorkspace
&
dataWS
);
std
::
vector
<
coord_t
>
getValuesFromOtherDimensions
(
bool
&
skipNormalization
)
const
;
Kernel
::
Matrix
<
coord_t
>
findIntergratedDimensions
(
const
std
::
vector
<
coord_t
>
&
otherDimValues
,
bool
&
skipNormalization
);
/// function to calculate intersections of the trajectory with MDBoxes
/// function to calculate intersections of the trajectory with MDBoxes
std
::
vector
<
Kernel
::
VMD
>
calculateIntersections
(
const
Geometry
::
IDetector_const_sptr
&
detector
);
std
::
vector
<
Kernel
::
VMD
>
calculateIntersections
(
const
Geometry
::
IDetector_const_sptr
&
detector
);
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/MDAlgorithms/src/SXDMDNorm.cpp
+
118
−
93
View file @
a32dcb48
...
@@ -100,90 +100,34 @@ namespace Mantid
...
@@ -100,90 +100,34 @@ namespace Mantid
void
SXDMDNorm
::
exec
()
void
SXDMDNorm
::
exec
()
{
{
initCaches
();
initCaches
();
auto
outputWS
=
binInputWS
();
setProperty
<
Workspace_sptr
>
(
"OutputWorkspace"
,
outputWS
);
createNormalizationWS
(
*
outputWS
);
// Check for other dimensions if we could measure anything in the original data
// Check for other dimensions if we could measure anything in the original data
bool
skipNormalization
=
false
;
bool
skipNormalization
=
false
;
const
std
::
vector
<
coord_t
>
otherValues
=
getValuesFromOtherDimensions
(
skipNormalization
);
const
std
::
vector
<
coord_t
>
otherValues
=
getValuesFromOtherDimensions
(
skipNormalization
);
auto
outputWS
=
binInputWS
();
const
auto
affineMat
=
findIntergratedDimensions
(
otherValues
,
skipNormalization
);
this
->
setProperty
<
Workspace_sptr
>
(
"OutputWorkspace"
,
outputWS
);
// Copy the MDHisto workspace, and change signals and errors to 0.
m_normWS
=
boost
::
make_shared
<
MDHistoWorkspace
>
(
*
outputWS
);
m_normWS
->
setTo
(
0.
,
0.
,
0.
);
//get indices of the original dimensions in the output workspace, and if not found, the corresponding dimension is integrated
Kernel
::
Matrix
<
coord_t
>
mat
=
m_normWS
->
getTransformFromOriginal
(
0
)
->
makeAffineMatrix
();
for
(
size_t
row
=
0
;
row
<
mat
.
numRows
()
-
1
;
row
++
)
//affine matrix, ignore last row
{
if
(
mat
[
row
][
0
]
==
1.
)
{
m_hIntegrated
=
false
;
m_hIdx
=
row
;
if
(
m_hmin
<
m_normWS
->
getDimension
(
row
)
->
getMinimum
())
m_hmin
=
m_normWS
->
getDimension
(
row
)
->
getMinimum
();
if
(
m_hmax
>
m_normWS
->
getDimension
(
row
)
->
getMaximum
())
m_hmax
=
m_normWS
->
getDimension
(
row
)
->
getMaximum
();
if
((
m_hmin
>
m_normWS
->
getDimension
(
row
)
->
getMaximum
())
||
(
m_hmax
<
m_normWS
->
getDimension
(
row
)
->
getMinimum
()))
{
skipNormalization
=
true
;
}
}
if
(
mat
[
row
][
1
]
==
1.
)
{
m_kIntegrated
=
false
;
m_kIdx
=
row
;
if
(
m_kmin
<
m_normWS
->
getDimension
(
row
)
->
getMinimum
())
m_kmin
=
m_normWS
->
getDimension
(
row
)
->
getMinimum
();
if
(
m_kmax
>
m_normWS
->
getDimension
(
row
)
->
getMaximum
())
m_kmax
=
m_normWS
->
getDimension
(
row
)
->
getMaximum
();
if
((
m_kmin
>
m_normWS
->
getDimension
(
row
)
->
getMaximum
())
||
(
m_kmax
<
m_normWS
->
getDimension
(
row
)
->
getMinimum
()))
{
skipNormalization
=
true
;
}
}
if
(
mat
[
row
][
2
]
==
1.
)
{
m_lIntegrated
=
false
;
m_lIdx
=
row
;
if
(
m_lmin
<
m_normWS
->
getDimension
(
row
)
->
getMinimum
())
m_lmin
=
m_normWS
->
getDimension
(
row
)
->
getMinimum
();
if
(
m_lmax
>
m_normWS
->
getDimension
(
row
)
->
getMaximum
())
m_lmax
=
m_normWS
->
getDimension
(
row
)
->
getMaximum
();
if
((
m_lmin
>
m_normWS
->
getDimension
(
row
)
->
getMaximum
())
||
(
m_lmax
<
m_normWS
->
getDimension
(
row
)
->
getMinimum
()))
{
skipNormalization
=
true
;
}
for
(
size_t
col
=
3
;
col
<
mat
.
numCols
()
-
1
;
col
++
)
//affine matrix, ignore last column
{
if
(
mat
[
row
][
col
]
==
1.
)
{
double
val
=
otherValues
.
at
(
col
-
3
);
if
((
val
>
m_normWS
->
getDimension
(
row
)
->
getMaximum
())
||
(
val
<
m_normWS
->
getDimension
(
row
)
->
getMinimum
()))
{
skipNormalization
=
true
;
}
}
}
}
}
auto
&
hDim
=
*
m_normWS
->
getDimension
(
m_hIdx
);
auto
&
hDim
=
*
m_normWS
->
getDimension
(
m_hIdx
);
m_hX
.
resize
(
hDim
.
getNBins
()
);
m_hX
.
resize
(
hDim
.
getNBins
()
);
for
(
size_t
i
=
0
;
i
<
m_hX
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
m_hX
.
size
();
++
i
)
{
{
m_hX
[
i
]
=
hDim
.
getX
(
i
);
m_hX
[
i
]
=
hDim
.
getX
(
i
);
}
}
auto
&
kDim
=
*
m_normWS
->
getDimension
(
m_kIdx
);
auto
&
kDim
=
*
m_normWS
->
getDimension
(
m_kIdx
);
m_kX
.
resize
(
kDim
.
getNBins
()
);
m_kX
.
resize
(
kDim
.
getNBins
()
);
for
(
size_t
i
=
0
;
i
<
m_kX
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
m_kX
.
size
();
++
i
)
{
{
m_kX
[
i
]
=
kDim
.
getX
(
i
);
m_kX
[
i
]
=
kDim
.
getX
(
i
);
}
}
auto
&
lDim
=
*
m_normWS
->
getDimension
(
m_lIdx
);
auto
&
lDim
=
*
m_normWS
->
getDimension
(
m_lIdx
);
m_lX
.
resize
(
lDim
.
getNBins
()
);
m_lX
.
resize
(
lDim
.
getNBins
()
);
for
(
size_t
i
=
0
;
i
<
m_lX
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
m_lX
.
size
();
++
i
)
{
{
m_lX
[
i
]
=
lDim
.
getX
(
i
);
m_lX
[
i
]
=
lDim
.
getX
(
i
);
}
}
API
::
MatrixWorkspace_const_sptr
fW
=
getProperty
(
"FluxWorkspace"
);
API
::
MatrixWorkspace_const_sptr
fW
=
getProperty
(
"FluxWorkspace"
);
DataObjects
::
EventWorkspace_const_sptr
fluxW
=
boost
::
dynamic_pointer_cast
<
const
DataObjects
::
EventWorkspace
>
(
fW
);
DataObjects
::
EventWorkspace_const_sptr
fluxW
=
boost
::
dynamic_pointer_cast
<
const
DataObjects
::
EventWorkspace
>
(
fW
);
m_kiMin
=
fluxW
->
getEventXMin
();
m_kiMin
=
fluxW
->
getEventXMin
();
...
@@ -265,7 +209,7 @@ namespace Mantid
...
@@ -265,7 +209,7 @@ namespace Mantid
std
::
transform
(
pos
.
begin
(),
pos
.
begin
()
+
sizeOfMVD
,
pos
.
begin
(),
std
::
bind2nd
(
std
::
multiplies
<
coord_t
>
(),
0.5
)
);
std
::
transform
(
pos
.
begin
(),
pos
.
begin
()
+
sizeOfMVD
,
pos
.
begin
(),
std
::
bind2nd
(
std
::
multiplies
<
coord_t
>
(),
0.5
)
);
std
::
copy
(
otherValues
.
begin
(),
otherValues
.
end
(),
pos
.
begin
()
+
sizeOfMVD
);
std
::
copy
(
otherValues
.
begin
(),
otherValues
.
end
(),
pos
.
begin
()
+
sizeOfMVD
);
std
::
vector
<
coord_t
>
posNew
=
m
at
*
pos
;
std
::
vector
<
coord_t
>
posNew
=
affineM
at
*
pos
;
size_t
linIndex
=
m_normWS
->
getLinearIndexAtCoord
(
posNew
.
data
());
size_t
linIndex
=
m_normWS
->
getLinearIndexAtCoord
(
posNew
.
data
());
if
(
linIndex
!=
size_t
(
-
1
))
if
(
linIndex
!=
size_t
(
-
1
))
...
@@ -303,7 +247,28 @@ namespace Mantid
...
@@ -303,7 +247,28 @@ namespace Mantid
this
->
setProperty
(
"OutputNormalizationWorkspace"
,
m_normWS
);
this
->
setProperty
(
"OutputNormalizationWorkspace"
,
m_normWS
);
}
}
/**
* Set up starting values for cached variables
*/
void
SXDMDNorm
::
initCaches
()
{
m_inputWS
=
getProperty
(
"InputWorkspace"
);
if
(
inputEnergyMode
()
!=
"Elastic"
)
{
throw
std
::
invalid_argument
(
"Invalid energy transfer mode. Algorithm currently only supports elastic data."
);
}
// Min/max dimension values
const
auto
hdim
(
m_inputWS
->
getDimension
(
0
)),
kdim
(
m_inputWS
->
getDimension
(
1
)),
ldim
(
m_inputWS
->
getDimension
(
2
));
m_hmin
=
hdim
->
getMinimum
();
m_kmin
=
kdim
->
getMinimum
();
m_lmin
=
ldim
->
getMinimum
();
m_hmax
=
hdim
->
getMaximum
();
m_kmax
=
kdim
->
getMaximum
();
m_lmax
=
ldim
->
getMaximum
();
}
/**
/**
* Currently looks for the ConvertToMD algorithm in the history
* Currently looks for the ConvertToMD algorithm in the history
* @return A string donating the energy transfer mode of the input workspace
* @return A string donating the energy transfer mode of the input workspace
...
@@ -341,24 +306,38 @@ namespace Mantid
...
@@ -341,24 +306,38 @@ namespace Mantid
}
}
/**
/**
* Set up starting values for cached variables
* Runs the BinMD algorithm on the input to provide the output workspace
* All slicing algorithm properties are passed along
* @return MDHistoWorkspace as a result of the binning
*/
*/
void
SXDMDNorm
::
in
itCaches
()
MDHistoWorkspace_sptr
SXDMDNorm
::
b
in
InputWS
()
{
{
m_inputWS
=
getProperty
(
"InputWorkspace"
);
const
auto
&
props
=
getProperties
();
if
(
inputEnergyMode
()
!=
"Elastic"
)
IAlgorithm_sptr
binMD
=
createChildAlgorithm
(
"BinMD"
,
0.0
,
0.3
);
binMD
->
setPropertyValue
(
"AxisAligned"
,
"1"
);
for
(
auto
it
=
props
.
begin
();
it
!=
props
.
end
();
++
it
)
{
{
throw
std
::
invalid_argument
(
"Invalid energy transfer mode. Algorithm currently only supports elastic data."
);
const
auto
&
propName
=
(
*
it
)
->
name
();
if
(
propName
!=
"FluxWorkspace"
&&
propName
!=
"SolidAngleWorkspace"
&&
propName
!=
"OutputNormalizationWorkspace"
)
{
binMD
->
setPropertyValue
(
propName
,(
*
it
)
->
value
());
}
}
}
// Min/max dimension values
binMD
->
executeAsChildAlg
();
const
auto
hdim
(
m_inputWS
->
getDimension
(
0
)),
kdim
(
m_inputWS
->
getDimension
(
1
)),
Workspace_sptr
outputWS
=
binMD
->
getProperty
(
"OutputWorkspace"
);
ldim
(
m_inputWS
->
getDimension
(
2
));
return
boost
::
dynamic_pointer_cast
<
MDHistoWorkspace
>
(
outputWS
);
m_hmin
=
hdim
->
getMinimum
();
}
m_kmin
=
kdim
->
getMinimum
();
m_lmin
=
ldim
->
getMinimum
();
/**
m_hmax
=
hdim
->
getMaximum
();
* Create & cached the normalization workspace
m_kmax
=
kdim
->
getMaximum
();
* @param dataWS The binned workspace that will be used for the data
m_lmax
=
ldim
->
getMaximum
();
*/
void
SXDMDNorm
::
createNormalizationWS
(
const
MDHistoWorkspace
&
dataWS
)
{
// Copy the MDHisto workspace, and change signals and errors to 0.
m_normWS
=
boost
::
make_shared
<
MDHistoWorkspace
>
(
dataWS
);
m_normWS
->
setTo
(
0.
,
0.
,
0.
);
}
}
/**
/**
...
@@ -393,27 +372,73 @@ namespace Mantid
...
@@ -393,27 +372,73 @@ namespace Mantid
}
}
/**
/**
* Runs the BinMD algorithm on the input to provide the output workspace
* Checks the normalization workspace against the indices of the original dimensions.
* All slicing algorithm properties are passed along
* If not found, the corresponding dimension is integrated
* @return MDHistoWorkspace as a result of the binning
* @param otherDimValues Values from non-HKL dimensions
* @param skipNormalization [InOut] Sets the flag true if normalization values are outside of original inputs
* @return Affine trasform matrix
*/
*/
MDHistoWorkspace_sptr
SXDMDNorm
::
binInputWS
()
Kernel
::
Matrix
<
coord_t
>
SXDMDNorm
::
findIntergratedDimensions
(
const
std
::
vector
<
coord_t
>
&
otherDimValues
,
bool
&
skipNormalization
)
{
{
const
auto
&
props
=
getProperties
();
// Get indices of the original dimensions in the output workspace,
IAlgorithm_sptr
binMD
=
createChildAlgorithm
(
"BinMD"
,
0.0
,
0.3
);
// and if not found, the corresponding dimension is integrated
binMD
->
setPropertyValue
(
"AxisAligned"
,
"1"
);
Kernel
::
Matrix
<
coord_t
>
affineMat
=
m_normWS
->
getTransformFromOriginal
(
0
)
->
makeAffineMatrix
();
for
(
auto
it
=
props
.
begin
();
it
!=
props
.
end
();
++
it
)
const
size_t
nrm1
=
affineMat
.
numRows
()
-
1
;
const
size_t
ncm1
=
affineMat
.
numCols
()
-
1
;
for
(
size_t
row
=
0
;
row
<
nrm1
;
row
++
)
//affine matrix, ignore last row
{
{
const
auto
&
propNa
me
=
(
*
it
)
->
name
(
);
const
auto
di
me
n
=
m_normWS
->
getDimension
(
row
);
if
(
propName
!=
"FluxWorkspace"
&&
propName
!=
"SolidAngleWorkspace"
&&
const
auto
dimMin
(
dimen
->
getMinimum
()),
dimMax
(
dimen
->
getMaximum
());
propName
!=
"OutputNormalizationWorkspace"
)
if
(
affineMat
[
row
][
0
]
==
1.
)
{
{
binMD
->
setPropertyValue
(
propName
,(
*
it
)
->
value
());
m_hIntegrated
=
false
;
m_hIdx
=
row
;
if
(
m_hmin
<
dimMin
)
m_hmin
=
dimMin
;
if
(
m_hmax
>
dimMax
)
m_hmax
=
dimMax
;
if
(
m_hmin
>
dimMax
||
m_hmax
<
dimMin
)
{
skipNormalization
=
true
;
}
}
if
(
affineMat
[
row
][
1
]
==
1.
)
{
m_kIntegrated
=
false
;
m_kIdx
=
row
;
if
(
m_kmin
<
dimMin
)
m_kmin
=
dimMin
;
if
(
m_kmax
>
dimMax
)
m_kmax
=
dimMax
;
if
(
m_kmin
>
dimMax
||
m_kmax
<
dimMin
)
{
skipNormalization
=
true
;
}
}
if
(
affineMat
[
row
][
2
]
==
1.
)
{
m_lIntegrated
=
false
;
m_lIdx
=
row
;
if
(
m_lmin
<
dimMin
)
m_lmin
=
dimMin
;
if
(
m_lmax
>
dimMax
)
m_lmax
=
dimMax
;
if
(
m_lmin
>
dimMax
||
m_lmax
<
dimMin
)
{
skipNormalization
=
true
;
}
for
(
size_t
col
=
3
;
col
<
ncm1
;
col
++
)
//affine matrix, ignore last column
{
if
(
affineMat
[
row
][
col
]
==
1.
)
{
double
val
=
otherDimValues
.
at
(
col
-
3
);
if
(
val
>
dimMax
||
val
<
dimMin
)
{
skipNormalization
=
true
;
}
}
}
}
}
}
}
binMD
->
executeAsChildAlg
();
Workspace_sptr
outputWS
=
binMD
->
getProperty
(
"OutputWorkspace"
);
return
affineMat
;
return
boost
::
dynamic_pointer_cast
<
MDHistoWorkspace
>
(
outputWS
);
}
}
/**
/**
...
...
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