Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
ada3d4d1
Commit
ada3d4d1
authored
Feb 20, 2018
by
Lynch, Vickie
Browse files
Refs #21752 unique peak number visible in tables
parent
ce3b323e
Changes
15
Hide whitespace changes
Inline
Side-by-side
Framework/Crystal/src/LoadIsawPeaks.cpp
View file @
ada3d4d1
...
...
@@ -76,7 +76,8 @@ int LoadIsawPeaks::confidence(Kernel::FileDescriptor &descriptor) const {
getWord
(
in
,
false
);
readToEndOfLine
(
in
,
true
);
confidence
=
95
;
}
catch
(
std
::
exception
&
)
{
}
catch
(
std
::
exception
&
)
{
}
return
confidence
;
...
...
@@ -86,11 +87,11 @@ int LoadIsawPeaks::confidence(Kernel::FileDescriptor &descriptor) const {
/** Initialize the algorithm's properties.
*/
void
LoadIsawPeaks
::
init
()
{
const
std
::
vector
<
std
::
string
>
exts
{
".peaks"
,
".integrate"
};
const
std
::
vector
<
std
::
string
>
exts
{
".peaks"
,
".integrate"
};
declareProperty
(
Kernel
::
make_unique
<
FileProperty
>
(
"Filename"
,
""
,
FileProperty
::
Load
,
exts
),
"Path to an ISAW-style .peaks filename."
);
declareProperty
(
make_unique
<
WorkspaceProperty
<
Workspace
>>
(
declareProperty
(
make_unique
<
WorkspaceProperty
<
Workspace
>
>
(
"OutputWorkspace"
,
""
,
Direction
::
Output
),
"Name of the output workspace."
);
}
...
...
@@ -236,7 +237,8 @@ std::string LoadIsawPeaks::readHeader(PeaksWorkspace_sptr outWS,
if
(
!
alg
->
execute
())
throw
std
::
runtime_error
(
"MaskDetectors Child Algorithm has not executed successfully"
);
}
catch
(...)
{
}
catch
(...)
{
g_log
.
error
(
"Can't execute MaskBTP algorithm"
);
}
}
...
...
@@ -334,6 +336,7 @@ DataObjects::Peak LoadIsawPeaks::readPeak(PeaksWorkspace_sptr outWS,
peak
.
setIntensity
(
Inti
);
peak
.
setSigmaIntensity
(
SigI
);
peak
.
setBinCount
(
IPK
);
peak
.
setPeakNumber
(
seqNum
);
// Return the peak
return
peak
;
}
...
...
@@ -510,7 +513,8 @@ void LoadIsawPeaks::appendFile(PeaksWorkspace_sptr outWS,
peak
.
setWavelength
(
wl
.
singleFromTOF
(
tof
));
// Add the peak to workspace
outWS
->
addPeak
(
peak
);
}
catch
(
std
::
runtime_error
&
e
)
{
}
catch
(
std
::
runtime_error
&
e
)
{
g_log
.
error
()
<<
"Error reading peak SEQN "
<<
seqNum
<<
" : "
<<
e
.
what
()
<<
'\n'
;
throw
std
::
runtime_error
(
"Corrupted input file. "
);
...
...
Framework/Crystal/src/SaveHKL.cpp
View file @
ada3d4d1
...
...
@@ -33,11 +33,11 @@ DECLARE_ALGORITHM(SaveHKL)
/** Initialize the algorithm's properties.
*/
void
SaveHKL
::
init
()
{
declareProperty
(
make_unique
<
WorkspaceProperty
<
PeaksWorkspace
>>
(
declareProperty
(
make_unique
<
WorkspaceProperty
<
PeaksWorkspace
>
>
(
"InputWorkspace"
,
""
,
Direction
::
Input
),
"An input PeaksWorkspace."
);
auto
mustBePositive
=
boost
::
make_shared
<
BoundedValidator
<
double
>>
();
auto
mustBePositive
=
boost
::
make_shared
<
BoundedValidator
<
double
>
>
();
mustBePositive
->
setLower
(
0.0
);
declareProperty
(
"ScalePeaks"
,
1.0
,
mustBePositive
,
"Multiply FSQ and sig(FSQ) by scaleFactor"
);
...
...
@@ -69,7 +69,7 @@ void SaveHKL::init() {
make_unique
<
FileProperty
>
(
"Filename"
,
""
,
FileProperty
::
Save
,
".hkl"
),
"Path to an hkl file to save."
);
std
::
vector
<
std
::
string
>
histoTypes
{
"Bank"
,
"RunNumber"
,
""
};
std
::
vector
<
std
::
string
>
histoTypes
{
"Bank"
,
"RunNumber"
,
""
};
declareProperty
(
"SortBy"
,
histoTypes
[
2
],
boost
::
make_shared
<
StringListValidator
>
(
histoTypes
),
"Sort the histograms by bank, run number or both (default)."
);
...
...
@@ -78,7 +78,7 @@ void SaveHKL::init() {
declareProperty
(
"WidthBorder"
,
EMPTY_INT
(),
"Width of border of detectors"
);
declareProperty
(
"MinIntensity"
,
EMPTY_DBL
(),
mustBePositive
,
"The minimum Intensity"
);
declareProperty
(
make_unique
<
WorkspaceProperty
<
PeaksWorkspace
>>
(
declareProperty
(
make_unique
<
WorkspaceProperty
<
PeaksWorkspace
>
>
(
"OutputWorkspace"
,
"SaveHKLOutput"
,
Direction
::
Output
),
"Output PeaksWorkspace"
);
declareProperty
(
...
...
@@ -88,7 +88,7 @@ void SaveHKL::init() {
"DirectionCosines"
,
false
,
"Extra columns (22 total) in file if true for direction cosines.
\n
"
"If false, original 14 columns (default)."
);
const
std
::
vector
<
std
::
string
>
exts
{
".mat"
,
".ub"
,
".txt"
};
const
std
::
vector
<
std
::
string
>
exts
{
".mat"
,
".ub"
,
".txt"
};
declareProperty
(
Kernel
::
make_unique
<
FileProperty
>
(
"UBFilename"
,
""
,
FileProperty
::
OptionalLoad
,
exts
),
"Path to an ISAW-style UB matrix text file only needed for "
...
...
@@ -185,7 +185,7 @@ void SaveHKL::exec() {
std
::
string
bankPart
=
"?"
;
// We must sort the peaks first by run, then bank #, and save the list of
// workspace indices of it
typedef
std
::
map
<
int
,
std
::
vector
<
size_t
>>
bankMap_t
;
typedef
std
::
map
<
int
,
std
::
vector
<
size_t
>
>
bankMap_t
;
typedef
std
::
map
<
int
,
bankMap_t
>
runMap_t
;
std
::
set
<
int
>
uniqueBanks
;
std
::
set
<
int
>
uniqueRuns
;
...
...
@@ -221,8 +221,8 @@ void SaveHKL::exec() {
}
bool
correctPeaks
=
getProperty
(
"ApplyAnvredCorrections"
);
std
::
vector
<
std
::
vector
<
double
>>
spectra
;
std
::
vector
<
std
::
vector
<
double
>>
time
;
std
::
vector
<
std
::
vector
<
double
>
>
spectra
;
std
::
vector
<
std
::
vector
<
double
>
>
time
;
int
iSpec
=
0
;
m_smu
=
getProperty
(
"LinearScatteringCoef"
);
// in 1/cm
m_amu
=
getProperty
(
"LinearAbsorptionCoef"
);
// in 1/cm
...
...
@@ -345,6 +345,7 @@ void SaveHKL::exec() {
continue
;
}
int
run
=
p
.
getRunNumber
();
int
seqNum
=
p
.
getPeakNumber
();
int
bank
=
0
;
std
::
string
bankName
=
p
.
getBankName
();
int
nCols
,
nRows
;
...
...
@@ -546,7 +547,7 @@ void SaveHKL::exec() {
out
<<
std
::
setw
(
6
)
<<
run
;
out
<<
std
::
setw
(
6
)
<<
wi
+
1
;
out
<<
std
::
setw
(
6
)
<<
seqNum
;
out
<<
std
::
setw
(
7
)
<<
std
::
fixed
<<
std
::
setprecision
(
4
)
<<
transmission
;
...
...
@@ -687,8 +688,8 @@ double SaveHKL::absor_sphere(double &twoth, double &wl, double &tbar) {
}
double
SaveHKL
::
spectrumCalc
(
double
TOF
,
int
iSpec
,
std
::
vector
<
std
::
vector
<
double
>>
time
,
std
::
vector
<
std
::
vector
<
double
>>
spectra
,
std
::
vector
<
std
::
vector
<
double
>
>
time
,
std
::
vector
<
std
::
vector
<
double
>
>
spectra
,
size_t
id
)
{
double
spect
=
0
;
if
(
iSpec
==
1
)
{
...
...
@@ -716,9 +717,9 @@ double SaveHKL::spectrumCalc(double TOF, int iSpec,
for
(
i
=
1
;
i
<
spectra
[
id
].
size
();
++
i
)
if
(
TOF
<
time
[
id
][
i
])
break
;
spect
=
spectra
[
id
][
i
-
1
]
+
(
TOF
-
time
[
id
][
i
-
1
])
/
(
time
[
id
][
i
]
-
time
[
id
][
i
-
1
])
*
(
spectra
[
id
][
i
]
-
spectra
[
id
][
i
-
1
]);
spect
=
spectra
[
id
][
i
-
1
]
+
(
TOF
-
time
[
id
][
i
-
1
])
/
(
time
[
id
][
i
]
-
time
[
id
][
i
-
1
])
*
(
spectra
[
id
][
i
]
-
spectra
[
id
][
i
-
1
]);
}
return
spect
;
...
...
Framework/Crystal/src/SaveIsawPeaks.cpp
View file @
ada3d4d1
...
...
@@ -27,7 +27,7 @@ DECLARE_ALGORITHM(SaveIsawPeaks)
/** Initialize the algorithm's properties.
*/
void
SaveIsawPeaks
::
init
()
{
declareProperty
(
make_unique
<
WorkspaceProperty
<
PeaksWorkspace
>>
(
declareProperty
(
make_unique
<
WorkspaceProperty
<
PeaksWorkspace
>
>
(
"InputWorkspace"
,
""
,
Direction
::
Input
,
boost
::
make_shared
<
InstrumentValidator
>
()),
"An input PeaksWorkspace with an instrument."
);
...
...
@@ -35,13 +35,13 @@ void SaveIsawPeaks::init() {
declareProperty
(
"AppendFile"
,
false
,
"Append to file if true.
\n
"
"If false, new file (default)."
);
const
std
::
vector
<
std
::
string
>
exts
{
".peaks"
,
".integrate"
};
const
std
::
vector
<
std
::
string
>
exts
{
".peaks"
,
".integrate"
};
declareProperty
(
Kernel
::
make_unique
<
FileProperty
>
(
"Filename"
,
""
,
FileProperty
::
Save
,
exts
),
"Path to an ISAW-style peaks or integrate file to save."
);
declareProperty
(
make_unique
<
WorkspaceProperty
<
Workspace2D
>>
(
make_unique
<
WorkspaceProperty
<
Workspace2D
>
>
(
"ProfileWorkspace"
,
""
,
Direction
::
Input
,
PropertyMode
::
Optional
),
"An optional Workspace2D of profiles from integrating cylinder."
);
}
...
...
@@ -62,9 +62,9 @@ void SaveIsawPeaks::exec() {
// We must sort the peaks first by run, then bank #, and save the list of
// workspace indices of it
typedef
std
::
map
<
int
,
std
::
vector
<
size_t
>>
bankMap_t
;
typedef
std
::
map
<
int
,
std
::
vector
<
size_t
>
>
bankMap_t
;
typedef
std
::
map
<
int
,
bankMap_t
>
runMap_t
;
std
::
set
<
int
,
std
::
less
<
int
>>
uniqueBanks
;
std
::
set
<
int
,
std
::
less
<
int
>
>
uniqueBanks
;
if
(
!
inst
)
throw
std
::
runtime_error
(
"No instrument in the Workspace. Cannot save DetCal file."
);
...
...
@@ -310,7 +310,7 @@ void SaveIsawPeaks::exec() {
Peak
&
p
=
peaks
[
wi
];
// Sequence (run) number
out
<<
"3"
<<
std
::
setw
(
7
)
<<
seqNum
;
out
<<
"3"
<<
std
::
setw
(
7
)
<<
p
.
getPeakNumber
()
;
// HKL's are flipped by -1 because of the internal Q convention
// unless Crystallography convention
...
...
Framework/Crystal/src/SortHKL.cpp
View file @
ada3d4d1
...
...
@@ -133,6 +133,8 @@ void SortHKL::exec() {
std
::
cout
<<
e
<<
" "
;
std
::
cout
<<
"
\n
"
;
auto
zScores
=
Kernel
::
getZscore
(
intensities
);
if
(
zScores
.
size
()
>
maxPeaks
)
maxPeaks
=
zScores
.
size
();
// Possibly remove outliers.
auto
outliersRemoved
=
unique
.
second
.
removeOutliers
(
sigmaCritical
);
...
...
@@ -183,7 +185,7 @@ void SortHKL::exec() {
MatrixWorkspace_sptr
UniqWksp2
=
Mantid
::
API
::
WorkspaceFactory
::
Instance
().
create
(
"Workspace2D"
,
counter
,
20
,
20
);
maxPeaks
,
maxPeaks
);
for
(
int64_t
i
=
0
;
i
<
counter
;
++
i
)
{
auto
&
outSpec
=
UniqWksp2
->
getSpectrum
(
i
);
const
auto
&
inSpec
=
UniqWksp
->
getSpectrum
(
i
);
...
...
Framework/DataObjects/inc/MantidDataObjects/Peak.h
View file @
ada3d4d1
...
...
@@ -111,12 +111,12 @@ public:
Mantid
::
Kernel
::
V3D
getDetectorPosition
()
const
override
;
Mantid
::
Kernel
::
V3D
getDetectorPositionNoCheck
()
const
override
;
void
setQSampleFrame
(
const
Mantid
::
Kernel
::
V3D
&
QSampleFrame
,
boost
::
optional
<
double
>
detectorDistance
=
boost
::
none
)
override
;
void
setQLabFrame
(
const
Mantid
::
Kernel
::
V3D
&
QLabFrame
,
boost
::
optional
<
double
>
detectorDistance
=
boost
::
none
)
override
;
void
setQSampleFrame
(
const
Mantid
::
Kernel
::
V3D
&
QSampleFrame
,
boost
::
optional
<
double
>
detectorDistance
=
boost
::
none
)
override
;
void
setQLabFrame
(
const
Mantid
::
Kernel
::
V3D
&
QLabFrame
,
boost
::
optional
<
double
>
detectorDistance
=
boost
::
none
)
override
;
void
setWavelength
(
double
wavelength
)
override
;
double
getWavelength
()
const
override
;
...
...
@@ -149,6 +149,8 @@ public:
int
getCol
()
const
override
;
void
setRow
(
int
m_row
);
void
setCol
(
int
m_col
);
void
setPeakNumber
(
int
m_peakNumber
);
int
getPeakNumber
()
const
override
;
virtual
Mantid
::
Kernel
::
V3D
getDetPos
()
const
override
;
double
getL1
()
const
override
;
...
...
@@ -242,6 +244,9 @@ private:
double
m_orig_K
;
double
m_orig_L
;
// keep peak number
int
m_peakNumber
;
/// List of contributing detectors IDs
std
::
set
<
int
>
m_detIDs
;
...
...
Framework/DataObjects/src/Peak.cpp
View file @
ada3d4d1
...
...
@@ -29,7 +29,7 @@ Peak::Peak()
m_finalEnergy
(
0.
),
m_GoniometerMatrix
(
3
,
3
,
true
),
m_InverseGoniometerMatrix
(
3
,
3
,
true
),
m_runNumber
(
0
),
m_monitorCount
(
0
),
m_row
(
-
1
),
m_col
(
-
1
),
m_orig_H
(
0
),
m_orig_K
(
0
),
m_orig_L
(
0
),
m_peakShape
(
boost
::
make_shared
<
NoShape
>
())
{
m_peakNumber
(
0
),
m_peakShape
(
boost
::
make_shared
<
NoShape
>
())
{
convention
=
Kernel
::
ConfigService
::
Instance
().
getString
(
"Q.convention"
);
}
...
...
@@ -169,7 +169,7 @@ Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering,
m_binCount
(
0
),
m_GoniometerMatrix
(
3
,
3
,
true
),
m_InverseGoniometerMatrix
(
3
,
3
,
true
),
m_runNumber
(
0
),
m_monitorCount
(
0
),
m_row
(
-
1
),
m_col
(
-
1
),
m_orig_H
(
0
),
m_orig_K
(
0
),
m_orig_L
(
0
),
m_peakShape
(
boost
::
make_shared
<
NoShape
>
())
{
m_peakNumber
(
0
),
m_peakShape
(
boost
::
make_shared
<
NoShape
>
())
{
convention
=
Kernel
::
ConfigService
::
Instance
().
getString
(
"Q.convention"
);
this
->
setInstrument
(
m_inst
);
this
->
setWavelength
(
m_Wavelength
);
...
...
@@ -197,8 +197,9 @@ Peak::Peak(const Peak &other)
m_row
(
other
.
m_row
),
m_col
(
other
.
m_col
),
sourcePos
(
other
.
sourcePos
),
samplePos
(
other
.
samplePos
),
detPos
(
other
.
detPos
),
m_orig_H
(
other
.
m_orig_H
),
m_orig_K
(
other
.
m_orig_K
),
m_orig_L
(
other
.
m_orig_L
),
m_detIDs
(
other
.
m_detIDs
),
m_peakShape
(
other
.
m_peakShape
->
clone
()),
convention
(
other
.
convention
)
{}
m_orig_L
(
other
.
m_orig_L
),
m_peakNumber
(
other
.
m_peakNumber
),
m_detIDs
(
other
.
m_detIDs
),
m_peakShape
(
other
.
m_peakShape
->
clone
()),
convention
(
other
.
convention
)
{}
//----------------------------------------------------------------------------------------------
/** Constructor making a Peak from IPeak interface
...
...
@@ -218,7 +219,7 @@ Peak::Peak(const Geometry::IPeak &ipeak)
m_runNumber
(
ipeak
.
getRunNumber
()),
m_monitorCount
(
ipeak
.
getMonitorCount
()),
m_row
(
ipeak
.
getRow
()),
m_col
(
ipeak
.
getCol
()),
m_orig_H
(
0.
),
m_orig_K
(
0.
),
m_orig_L
(
0.
),
m_peakShape
(
boost
::
make_shared
<
NoShape
>
())
{
m_peakNumber
(
0
),
m_peakShape
(
boost
::
make_shared
<
NoShape
>
())
{
convention
=
Kernel
::
ConfigService
::
Instance
().
getString
(
"Q.convention"
);
if
(
fabs
(
m_InverseGoniometerMatrix
.
Invert
())
<
1e-8
)
throw
std
::
invalid_argument
(
...
...
@@ -870,6 +871,11 @@ int Peak::getRow() const { return m_row; }
* Returns -1 if it could not find it. */
int
Peak
::
getCol
()
const
{
return
m_col
;
}
// -------------------------------------------------------------------------------------
/**Returns the unique peak number
* Returns -1 if it could not find it. */
int
Peak
::
getPeakNumber
()
const
{
return
m_peakNumber
;
}
// -------------------------------------------------------------------------------------
/** For RectangularDetectors only, sets the row (y) of the pixel of the
* detector.
...
...
@@ -882,6 +888,13 @@ void Peak::setRow(int m_row) { this->m_row = m_row; }
* @param m_col :: col value */
void
Peak
::
setCol
(
int
m_col
)
{
this
->
m_col
=
m_col
;
}
// -------------------------------------------------------------------------------------
/** Sets the unique peak number
* @param m_col :: col value */
void
Peak
::
setPeakNumber
(
int
m_peakNumber
)
{
this
->
m_peakNumber
=
m_peakNumber
;
}
// -------------------------------------------------------------------------------------
/** Return the detector position vector */
Mantid
::
Kernel
::
V3D
Peak
::
getDetPos
()
const
{
return
detPos
;
}
...
...
Framework/DataObjects/src/PeakColumn.cpp
View file @
ada3d4d1
...
...
@@ -31,7 +31,7 @@ const std::string typeFromName(const std::string &name) {
// We should enter the critical section if the map has not been fully filled.
// Be sure to keep the value tested against in sync with the number of inserts
// below
if
(
TYPE_INDEX
.
size
()
!=
1
7
)
{
if
(
TYPE_INDEX
.
size
()
!=
1
8
)
{
PARALLEL_CRITICAL
(
fill_column_index_map
)
{
if
(
TYPE_INDEX
.
empty
())
// check again inside the critical block
{
...
...
@@ -53,6 +53,7 @@ const std::string typeFromName(const std::string &name) {
TYPE_INDEX
.
emplace
(
"Col"
,
"double"
);
TYPE_INDEX
.
emplace
(
"QLab"
,
"V3D"
);
TYPE_INDEX
.
emplace
(
"QSample"
,
"V3D"
);
TYPE_INDEX
.
emplace
(
"PeakNumber"
,
"int"
);
// If adding an entry, be sure to increment the size comparizon in the
// first line
}
...
...
@@ -152,6 +153,8 @@ void PeakColumn::print(size_t index, std::ostream &s) const {
s
<<
std
::
fixed
<<
std
::
setprecision
(
m_hklPrec
)
<<
peak
.
getK
();
}
else
if
(
m_name
==
"l"
)
{
s
<<
std
::
fixed
<<
std
::
setprecision
(
m_hklPrec
)
<<
peak
.
getL
();
}
else
if
(
m_name
==
"PeakNumber"
)
{
s
<<
peak
.
getPeakNumber
();
}
else
s
<<
peak
.
getValueByColName
(
m_name
);
s
.
flags
(
fflags
);
...
...
Framework/DataObjects/src/PeaksWorkspace.cpp
View file @
ada3d4d1
...
...
@@ -630,6 +630,7 @@ void PeaksWorkspace::initColumns() {
addPeakColumn
(
"Col"
);
addPeakColumn
(
"QLab"
);
addPeakColumn
(
"QSample"
);
addPeakColumn
(
"PeakNumber"
);
}
//---------------------------------------------------------------------------------------------
...
...
@@ -694,6 +695,7 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
std
::
vector
<
double
>
dSpacing
(
np
);
std
::
vector
<
double
>
TOF
(
np
);
std
::
vector
<
int
>
runNumber
(
np
);
std
::
vector
<
int
>
peakNumber
(
np
);
std
::
vector
<
double
>
goniometerMatrix
(
9
*
np
);
std
::
vector
<
std
::
string
>
shapes
(
np
);
...
...
@@ -715,6 +717,7 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
dSpacing
[
i
]
=
p
.
getDSpacing
();
TOF
[
i
]
=
p
.
getTOF
();
runNumber
[
i
]
=
p
.
getRunNumber
();
peakNumber
[
i
]
=
p
.
getPeakNumber
();
{
Matrix
<
double
>
gm
=
p
.
getGoniometerMatrix
();
goniometerMatrix
[
9
*
i
]
=
gm
[
0
][
0
];
...
...
@@ -861,6 +864,14 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
file
->
putAttr
(
"units"
,
"Not known"
);
// Units may need changing when known
file
->
closeData
();
// Peak Number column
file
->
writeData
(
"column_20"
,
peakNumber
);
file
->
openData
(
"column_20"
);
file
->
putAttr
(
"name"
,
"Peak Number"
);
file
->
putAttr
(
"interpret_as"
,
specifyInteger
);
file
->
putAttr
(
"units"
,
"Not known"
);
// Units may need changing when known
file
->
closeData
();
// Goniometer Matrix Column
std
::
vector
<
int
>
array_dims
;
array_dims
.
push_back
(
static_cast
<
int
>
(
peaks
.
size
()));
...
...
Framework/Geometry/inc/MantidGeometry/Crystal/IPeak.h
View file @
ada3d4d1
...
...
@@ -76,6 +76,9 @@ public:
virtual
double
getBinCount
()
const
=
0
;
virtual
void
setBinCount
(
double
m_BinCount
)
=
0
;
virtual
int
getPeakNumber
()
const
=
0
;
virtual
void
setPeakNumber
(
int
m_PeakNumber
)
=
0
;
virtual
Mantid
::
Kernel
::
Matrix
<
double
>
getGoniometerMatrix
()
const
=
0
;
virtual
void
setGoniometerMatrix
(
const
Mantid
::
Kernel
::
Matrix
<
double
>
&
m_GoniometerMatrix
)
=
0
;
...
...
Framework/Kernel/src/Statistics.cpp
View file @
ada3d4d1
...
...
@@ -68,7 +68,7 @@ double getMedian(const vector<TYPE> &data, const size_t num_data,
// return the average
return
(
left
+
right
)
/
2.
;
}
else
// Odd number
// Odd number
{
if
(
sorted
)
{
// If sorted and odd, just return the centre value
...
...
@@ -100,9 +100,10 @@ std::vector<double> getZscore(const vector<TYPE> &data) {
std
::
vector
<
double
>
Zscore
(
data
.
size
(),
0.
);
return
Zscore
;
}
double
divisor
=
stats
.
standard_deviation
/
data
.
size
();
for
(
auto
it
=
data
.
cbegin
();
it
!=
data
.
cend
();
++
it
)
{
double
tmp
=
static_cast
<
double
>
(
*
it
);
Zscore
.
push_back
(
fabs
(
(
tmp
-
stats
.
mean
)
/
stats
.
standard_deviation
))
;
Zscore
.
push_back
(
fabs
(
stats
.
mean
-
tmp
)
/
divisor
;
}
return
Zscore
;
}
...
...
@@ -158,7 +159,7 @@ Statistics getStatistics(const vector<TYPE> &data, const unsigned int flags) {
(
flags
&
StatOptions
::
CorrectedStdDev
));
if
(
stddev
)
{
using
namespace
boost
::
accumulators
;
accumulator_set
<
double
,
stats
<
tag
::
min
,
tag
::
max
,
tag
::
variance
>>
acc
;
accumulator_set
<
double
,
stats
<
tag
::
min
,
tag
::
max
,
tag
::
variance
>
>
acc
;
for
(
auto
&
value
:
data
)
{
acc
(
static_cast
<
double
>
(
value
));
}
...
...
@@ -175,7 +176,7 @@ Statistics getStatistics(const vector<TYPE> &data, const unsigned int flags) {
}
else
if
(
flags
&
StatOptions
::
Mean
)
{
using
namespace
boost
::
accumulators
;
accumulator_set
<
double
,
stats
<
tag
::
mean
>>
acc
;
accumulator_set
<
double
,
stats
<
tag
::
mean
>
>
acc
;
for
(
auto
&
value
:
data
)
{
acc
(
static_cast
<
double
>
(
value
));
}
...
...
Framework/MDAlgorithms/inc/MantidMDAlgorithms/FindPeaksMD.h
View file @
ada3d4d1
...
...
@@ -100,6 +100,8 @@ private:
Mantid
::
Geometry
::
Instrument_const_sptr
inst
;
/// Run number of the peaks
int
m_runNumber
;
/// Unique peak number
int
m_peakNumber
;
/// Dimension type
eDimensionType
dimType
;
/// Goniometer matrix
...
...
Framework/MDAlgorithms/src/FindPeaksMD.cpp
View file @
ada3d4d1
...
...
@@ -114,30 +114,30 @@ const std::string FindPeaksMD::numberOfEventsNormalization =
FindPeaksMD
::
FindPeaksMD
()
:
peakWS
(),
peakRadiusSquared
(),
DensityThresholdFactor
(
0.0
),
m_maxPeaks
(
0
),
m_addDetectors
(
true
),
m_densityScaleFactor
(
1e-6
),
prog
(
nullptr
),
inst
(),
m_runNumber
(
-
1
),
dimType
(),
m_goniometer
()
{}
m_runNumber
(
-
1
),
m_peakNumber
(
1
),
dimType
(),
m_goniometer
()
{}
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void
FindPeaksMD
::
init
()
{
declareProperty
(
make_unique
<
WorkspaceProperty
<
IMDWorkspace
>>
(
declareProperty
(
make_unique
<
WorkspaceProperty
<
IMDWorkspace
>
>
(
"InputWorkspace"
,
""
,
Direction
::
Input
),
"An input MDEventWorkspace or MDHistoWorkspace with at least "
"3 dimensions."
);
declareProperty
(
make_unique
<
PropertyWithValue
<
double
>>
(
"PeakDistanceThreshold"
,
0.1
,
Direction
::
Input
),
make_unique
<
PropertyWithValue
<
double
>
>
(
"PeakDistanceThreshold"
,
0.1
,
Direction
::
Input
),
"Threshold distance for rejecting peaks that are found to be too close "
"from each other.
\n
"
"This should be some multiple of the radius of a peak. Default: 0.1."
);
declareProperty
(
make_unique
<
PropertyWithValue
<
int64_t
>>
(
"MaxPeaks"
,
500
,
Direction
::
Input
),
declareProperty
(
make_unique
<
PropertyWithValue
<
int64_t
>
>
(
"MaxPeaks"
,
500
,
Direction
::
Input
),
"Maximum number of peaks to find. Default: 500."
);
std
::
vector
<
std
::
string
>
strategy
=
{
volumeNormalization
,
numberOfEventsNormalization
};
std
::
vector
<
std
::
string
>
strategy
=
{
volumeNormalization
,
numberOfEventsNormalization
};
declareProperty
(
"PeakFindingStrategy"
,
volumeNormalization
,
boost
::
make_shared
<
StringListValidator
>
(
strategy
),
...
...
@@ -156,7 +156,7 @@ void FindPeaksMD::init() {
"be larger than 1. Note that this approach does not work for event-based "
"raw data.
\n
"
);
declareProperty
(
make_unique
<
PropertyWithValue
<
double
>>
(
declareProperty
(
make_unique
<
PropertyWithValue
<
double
>
>
(
"DensityThresholdFactor"
,
10.0
,
Direction
::
Input
),
"The overall signal density of the workspace will be "
"multiplied by this factor
\n
"
...
...
@@ -170,7 +170,7 @@ void FindPeaksMD::init() {
Mantid
::
Kernel
::
ePropertyCriterion
::
IS_EQUAL_TO
,
volumeNormalization
));
declareProperty
(
make_unique
<
PropertyWithValue
<
double
>>
(
declareProperty
(
make_unique
<
PropertyWithValue
<
double
>
>
(
"SignalThresholdFactor"
,
1.5
,
Direction
::
Input
),
"The overal signal value (not density!) normalized by the "
"number of events is compared to the specified signal "
...
...
@@ -193,7 +193,7 @@ void FindPeaksMD::init() {
"only) for a constant wavelength. This only works for Q "
"sample workspaces."
);
auto
nonNegativeDbl
=
boost
::
make_shared
<
BoundedValidator
<
double
>>
();
auto
nonNegativeDbl
=
boost
::
make_shared
<
BoundedValidator
<
double
>
>
();
nonNegativeDbl
->
setLower
(
0
);
declareProperty
(
"Wavelength"
,
DBL_MAX
,
nonNegativeDbl
,
"Wavelength to use when calculating goniometer angle"
);
...
...
@@ -203,7 +203,7 @@ void FindPeaksMD::init() {
"CalculateGoniometerForCW"
,
Mantid
::
Kernel
::
ePropertyCriterion
::
IS_NOT_DEFAULT
));
declareProperty
(
make_unique
<
WorkspaceProperty
<
PeaksWorkspace
>>
(
declareProperty
(
make_unique
<
WorkspaceProperty
<
PeaksWorkspace
>
>
(
"OutputWorkspace"
,
""
,
Direction
::
Output
),
"An output PeaksWorkspace with the peaks' found positions."
);
...
...
@@ -212,7 +212,7 @@ void FindPeaksMD::init() {
"if it exists.
\n
"
"If unchecked, the output workspace is replaced (Default)."
);
auto
nonNegativeInt
=
boost
::
make_shared
<
BoundedValidator
<
int
>>
();
auto
nonNegativeInt
=
boost
::
make_shared
<
BoundedValidator
<
int
>
>
();
nonNegativeInt
->
setLower
(
0
);
declareProperty
(
"EdgePixels"
,
0
,
nonNegativeInt
,
"Remove peaks that are at pixels this close to edge. "
);
...
...
@@ -246,7 +246,8 @@ void FindPeaksMD::readExperimentInfo(const ExperimentInfo_sptr &ei,
Mantid
::
Kernel
::
Matrix
<
double
>
(
3
,
3
,
true
);
// Default IDENTITY matrix
try
{
m_goniometer
=
ei
->
mutableRun
().
getGoniometerMatrix
();
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
g_log
.
warning
()
<<
"Error finding goniometer matrix. It will not be set in "
"the peaks found.
\n
"
;
g_log
.
warning
()
<<
e
.
what
()
<<
'\n'
;
...
...
@@ -270,7 +271,8 @@ void FindPeaksMD::addPeak(const V3D &Q, const double binCount,
}
if
(
p
->
getDetectorID
()
!=
-
1
)
peakWS
->
addPeak
(
*
p
);
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
g_log
.
notice
()
<<
"Error creating peak at "
<<
Q
<<
" because of '"
<<
e
.
what
()
<<
"'. Peak will be skipped.
\n
"
;
}
...
...
@@ -304,9 +306,9 @@ FindPeaksMD::createPeak(const Mantid::Kernel::V3D &Q, const double binCount,
// Solve to find rotation matrix, assuming only rotation around y-axis
// A * X = B
Matrix
<
double
>
A
({
Q
[
0
],
Q
[
2
],
Q
[
2
],
-
Q
[
0
]},
2
,
2
);
Matrix
<
double
>
A
({
Q
[
0
],
Q
[
2
],
Q
[
2
],
-
Q
[
0
]
},
2
,
2
);
A
.
Invert
();
std
::
vector
<
double
>
B
{
Q_lab
[
0
],
Q_lab
[
2
]};
std
::
vector
<
double
>
B
{
Q_lab
[
0
],
Q_lab
[
2
]
};
std
::
vector
<
double
>
X
=
A
*
B
;
double
rot
=
atan2
(
X
[
1
],
X
[
0
]);
g_log
.
information
()
<<
"Found goniometer rotation to be "
...
...
@@ -330,7 +332,8 @@ FindPeaksMD::createPeak(const Mantid::Kernel::V3D &Q, const double binCount,
try
{
// Look for a detector
p
->
findDetector
(
tracer
);
}
catch
(...)
{
/* Ignore errors in ray-tracer */
}
catch
(...)
{
/* Ignore errors in ray-tracer */
}
p
->
setBinCount
(
binCount
);
...
...
@@ -500,8 +503,8 @@ void FindPeaksMD::findPeaks(typename MDEventWorkspace<MDE, nd>::sptr ws) {
if
(
nexp
>
1
)
{
MDBox
<
MDE
,
nd
>
*
mdbox
=
dynamic_cast
<
MDBox
<
MDE
,
nd
>
*>
(
box
);
typename
std
::
vector
<
MDE
>
&
events
=
mdbox
->
getEvents
();
if
(
std
::
none_of
(
events
.
cbegin
(),
events
.
cend
(),
[
&
iexp
,
&
nexp
](
MDE
event
)
{
if
(
std
::
none_of
(
events
.
cbegin
(),
events
.
cend
(),
[
&
iexp
,
&
nexp
](
MDE
event
)
{
return
event
.
getRunIndex
()
==
iexp
||
event
.
getRunIndex
()
>=
nexp
;
}))
continue
;
...
...
@@ -545,7 +548,8 @@ void FindPeaksMD::findPeaks(typename MDEventWorkspace<MDE, nd>::sptr ws) {
g_log
.
information
()
<<
"Add new peak with Q-center = "
<<
Q
[
0
]
<<
", "
<<
Q
[
1
]
<<
", "
<<
Q
[
2
]
<<
"
\n
"
;
}
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
g_log
.
notice
()
<<
"Error creating peak at "
<<
Q
<<
" because of '"
<<
e
.
what
()
<<
"'. Peak will be skipped.
\n
"
;
}
...
...
@@ -564,8 +568,8 @@ void FindPeaksMD::findPeaks(typename MDEventWorkspace<MDE, nd>::sptr ws) {
*
* @param ws :: MDHistoWorkspace
*/
void
FindPeaksMD
::
findPeaksHisto
(
Mantid
::
DataObjects
::
MDHistoWorkspace_sptr
ws
)
{
void
FindPeaksMD
::
findPeaksHisto
(
Mantid
::
DataObjects
::
MDHistoWorkspace_sptr
ws
)
{
size_t
nd
=
ws
->
getNumDims
();
if
(
nd
<
3
)
throw
std
::
invalid_argument
(
"Workspace must have at least 3 dimensions."
);
...
...
@@ -740,12 +744,16 @@ void FindPeaksMD::exec() {
}