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
db4305fe
Commit
db4305fe
authored
Nov 26, 2012
by
Gigg, Martyn Anthony
Browse files
Allow peak to store contributing detectors. Refs #6232
parent
391ceac5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Peak.h
View file @
db4305fe
...
...
@@ -33,15 +33,17 @@ namespace DataObjects
Peak
(
Geometry
::
Instrument_const_sptr
m_inst
,
int
m_DetectorID
,
double
m_Wavelength
,
Mantid
::
Kernel
::
V3D
HKL
,
Mantid
::
Kernel
::
Matrix
<
double
>
goniometer
);
Peak
(
Geometry
::
Instrument_const_sptr
m_inst
,
double
scattering
,
double
m_Wavelength
);
// Copy constructor is compiler-provided.
Peak
(
const
Peak
&
other
);
// Construct a peak from a reference to the interface
Peak
(
const
API
::
IPeak
&
ipeak
);
virtual
~
Peak
();
void
setInstrument
(
Geometry
::
Instrument_const_sptr
inst
);
void
setDetectorID
(
int
id
);
int
getDetectorID
()
const
;
void
setDetectorID
(
int
m_DetectorID
);
void
addContributingDetID
(
const
int
id
);
void
removeContributingDetector
(
const
int
id
);
const
std
::
set
<
int
>
&
getContributingDetIDs
()
const
;
void
setInstrument
(
Geometry
::
Instrument_const_sptr
inst
);
Geometry
::
IDetector_const_sptr
getDetector
()
const
;
Geometry
::
Instrument_const_sptr
getInstrument
()
const
;
...
...
@@ -104,7 +106,7 @@ namespace DataObjects
double
getValueByColName
(
const
std
::
string
&
name
)
const
;
pr
otec
te
d
:
pr
iva
te:
/// Shared pointer to the instrument (for calculating some values )
Geometry
::
Instrument_const_sptr
m_inst
;
...
...
@@ -171,6 +173,8 @@ namespace DataObjects
double
orig_K
;
double
orig_L
;
/// List of contributing detectors IDs
std
::
set
<
int
>
m_detIDs
;
};
...
...
Code/Mantid/Framework/DataObjects/src/Peak.cpp
View file @
db4305fe
...
...
@@ -159,60 +159,25 @@ namespace DataObjects
detPos
=
V3D
(
sin
(
scattering
),
0.0
,
cos
(
scattering
));
}
//----------------------------------------------------------------------------------------------
/** Constructor making a Peak from IPeak interface
*
* @param peak :: const reference to an IPeak object
* @return
*/
Peak
::
Peak
(
const
Peak
&
peak
)
:
m_inst
(
peak
.
m_inst
),
m_det
(
peak
.
m_det
),
m_BankName
(
peak
.
m_BankName
),
m_DetectorID
(
peak
.
m_DetectorID
),
m_H
(
peak
.
m_H
),
m_K
(
peak
.
m_K
),
m_L
(
peak
.
m_L
),
m_Intensity
(
peak
.
m_Intensity
),
m_SigmaIntensity
(
peak
.
m_SigmaIntensity
),
m_BinCount
(
peak
.
m_BinCount
),
m_InitialEnergy
(
peak
.
m_InitialEnergy
),
m_FinalEnergy
(
peak
.
m_FinalEnergy
),
m_GoniometerMatrix
(
peak
.
m_GoniometerMatrix
),
m_InverseGoniometerMatrix
(
peak
.
m_InverseGoniometerMatrix
),
m_RunNumber
(
peak
.
m_RunNumber
),
m_MonitorCount
(
peak
.
m_MonitorCount
),
m_Row
(
peak
.
m_Row
),
m_Col
(
peak
.
m_Col
),
sourcePos
(
peak
.
sourcePos
),
samplePos
(
peak
.
samplePos
),
detPos
(
peak
.
detPos
),
orig_H
(
peak
.
orig_H
),
orig_K
(
peak
.
orig_K
),
orig_L
(
peak
.
orig_L
)
{
}
//----------------------------------------------------------------------------------------------
/** Constructor making a Peak from IPeak interface
*
* @param ipeak :: const reference to an IPeak object
* @return
*/
Peak
::
Peak
(
const
API
::
IPeak
&
ipeak
)
:
m_H
(
ipeak
.
getH
()),
m_K
(
ipeak
.
getK
()),
m_L
(
ipeak
.
getL
()),
m_Intensity
(
ipeak
.
getIntensity
()),
m_SigmaIntensity
(
ipeak
.
getSigmaIntensity
()),
m_BinCount
(
ipeak
.
getBinCount
()),
m_InitialEnergy
(
ipeak
.
getInitialEnergy
()),
m_FinalEnergy
(
ipeak
.
getFinalEnergy
()),
m_GoniometerMatrix
(
ipeak
.
getGoniometerMatrix
()),
m_InverseGoniometerMatrix
(
ipeak
.
getGoniometerMatrix
()),
m_RunNumber
(
ipeak
.
getRunNumber
()),
m_MonitorCount
(
ipeak
.
getMonitorCount
())
Peak
::
Peak
(
const
API
::
IPeak
&
ipeak
)
:
IPeak
(
ipeak
),
m_H
(
ipeak
.
getH
()),
m_K
(
ipeak
.
getK
()),
m_L
(
ipeak
.
getL
()),
m_Intensity
(
ipeak
.
getIntensity
()),
m_SigmaIntensity
(
ipeak
.
getSigmaIntensity
()),
m_BinCount
(
ipeak
.
getBinCount
()),
m_InitialEnergy
(
ipeak
.
getInitialEnergy
()),
m_FinalEnergy
(
ipeak
.
getFinalEnergy
()),
m_GoniometerMatrix
(
ipeak
.
getGoniometerMatrix
()),
m_InverseGoniometerMatrix
(
ipeak
.
getGoniometerMatrix
()),
m_RunNumber
(
ipeak
.
getRunNumber
()),
m_MonitorCount
(
ipeak
.
getMonitorCount
())
{
if
(
fabs
(
m_InverseGoniometerMatrix
.
Invert
())
<
1e-8
)
throw
std
::
invalid_argument
(
"Peak::ctor(): Goniometer matrix must non-singular."
);
setInstrument
(
ipeak
.
getInstrument
());
...
...
@@ -250,40 +215,20 @@ namespace DataObjects
//----------------------------------------------------------------------------------------------
/** Set the
instrument (and save the source/sample pos).
*
Call setDetectorID AFTER this call.
*
* @param i
nst
:: I
nstrument sptr to use
/** Set the
detector ID of the pixel at the centre of the peak and look up and cache
*
values related to it. It also adds it to the list of contributing detectors for this peak but
*
does NOT remove the old centre.
* @param i
d
:: I
D of detector at the centre of the peak.
*/
void
Peak
::
set
Instrument
(
Geometry
::
Instrument_const_sptr
inst
)
void
Peak
::
set
DetectorID
(
int
id
)
{
m_inst
=
inst
;
if
(
!
inst
)
throw
std
::
runtime_error
(
"Peak::setInstrument(): No instrument is set!"
);
// Cache some positions
const
Geometry
::
IObjComponent_const_sptr
sourceObj
=
m_inst
->
getSource
();
if
(
sourceObj
==
NULL
)
throw
Exception
::
InstrumentDefinitionError
(
"Peak::setInstrument(): Failed to get source component from instrument"
);
const
Geometry
::
IObjComponent_const_sptr
sampleObj
=
m_inst
->
getSample
();
if
(
sampleObj
==
NULL
)
throw
Exception
::
InstrumentDefinitionError
(
"Peak::setInstrument(): Failed to get sample component from instrument"
);
sourcePos
=
sourceObj
->
getPos
();
samplePos
=
sampleObj
->
getPos
();
}
//----------------------------------------------------------------------------------------------
/** Set the detector ID and look up and cache values related to it.
*
* @param m_DetectorID :: ID of detector at the center of the peak
*/
void
Peak
::
setDetectorID
(
int
m_DetectorID
)
{
this
->
m_DetectorID
=
m_DetectorID
;
if
(
!
m_inst
)
throw
std
::
runtime_error
(
"Peak::setInstrument(): No instrument is set!"
);
this
->
m_det
=
m_inst
->
getDetector
(
this
->
m_DetectorID
);
this
->
m_det
=
m_inst
->
getDetector
(
id
);
if
(
!
m_det
)
throw
std
::
runtime_error
(
"Peak::setInstrument(): No detector was found!"
);
this
->
m_DetectorID
=
id
;
addContributingDetID
(
id
);
detPos
=
m_det
->
getPos
();
// We now look for the row/column. -1 if not found.
...
...
@@ -320,6 +265,73 @@ namespace DataObjects
m_Col
=
xy
.
first
;
}
//----------------------------------------------------------------------------------------------
/** Get the ID of the detector at the center of the peak */
int
Peak
::
getDetectorID
()
const
{
return
m_DetectorID
;
}
//----------------------------------------------------------------------------------------------
/**
* Add a detector ID that contributed to this peak
* @param id :: The ID of a detector that contributed to this peak
*/
void
Peak
::
addContributingDetID
(
const
int
id
)
{
m_detIDs
.
insert
(
id
);
}
//-------------------------------------------------------------------------------------
/**
* Removes an ID from the list of contributing detectors
* @param id :: This ID is removed from the list.
*/
void
Peak
::
removeContributingDetector
(
const
int
id
)
{
m_detIDs
.
erase
(
id
);
}
//----------------------------------------------------------------------------------------------
/**
* Return the set of detector IDs that contribute to this peak
* @returns A set of unique detector IDs that form this peak
*/
const
std
::
set
<
int
>
&
Peak
::
getContributingDetIDs
()
const
{
return
m_detIDs
;
}
//----------------------------------------------------------------------------------------------
/** Set the instrument (and save the source/sample pos).
* Call setDetectorID AFTER this call.
*
* @param inst :: Instrument sptr to use
*/
void
Peak
::
setInstrument
(
Geometry
::
Instrument_const_sptr
inst
)
{
m_inst
=
inst
;
if
(
!
inst
)
throw
std
::
runtime_error
(
"Peak::setInstrument(): No instrument is set!"
);
// Cache some positions
const
Geometry
::
IObjComponent_const_sptr
sourceObj
=
m_inst
->
getSource
();
if
(
sourceObj
==
NULL
)
throw
Exception
::
InstrumentDefinitionError
(
"Peak::setInstrument(): Failed to get source component from instrument"
);
const
Geometry
::
IObjComponent_const_sptr
sampleObj
=
m_inst
->
getSample
();
if
(
sampleObj
==
NULL
)
throw
Exception
::
InstrumentDefinitionError
(
"Peak::setInstrument(): Failed to get sample component from instrument"
);
sourcePos
=
sourceObj
->
getPos
();
samplePos
=
sampleObj
->
getPos
();
}
//----------------------------------------------------------------------------------------------
/** Return a shared ptr to the detector at center of peak. */
Geometry
::
IDetector_const_sptr
Peak
::
getDetector
()
const
{
return
m_det
;
}
/** Return a shared ptr to the instrument for this peak. */
Geometry
::
Instrument_const_sptr
Peak
::
getInstrument
()
const
{
return
m_inst
;
}
// -------------------------------------------------------------------------------------
/** Calculate the neutron wavelength (in angstroms) at the peak
...
...
@@ -532,15 +544,6 @@ namespace DataObjects
return
false
;
}
//----------------------------------------------------------------------------------------------
/** Return a shared ptr to the detector at center of peak. */
Geometry
::
IDetector_const_sptr
Peak
::
getDetector
()
const
{
return
m_det
;
}
/** Return a shared ptr to the instrument for this peak. */
Geometry
::
Instrument_const_sptr
Peak
::
getInstrument
()
const
{
return
m_inst
;
}
//----------------------------------------------------------------------------------------------
/** Return the run number this peak was measured at. */
int
Peak
::
getRunNumber
()
const
...
...
@@ -561,10 +564,6 @@ namespace DataObjects
void
Peak
::
setMonitorCount
(
double
m_MonitorCount
)
{
this
->
m_MonitorCount
=
m_MonitorCount
;
}
//----------------------------------------------------------------------------------------------
/** Get the ID of the detector at the center of the peak */
int
Peak
::
getDetectorID
()
const
{
return
m_DetectorID
;
}
//----------------------------------------------------------------------------------------------
/** Get the final neutron energy */
...
...
@@ -802,6 +801,7 @@ namespace DataObjects
}
}
// namespace Mantid
}
// namespace DataObjects
Code/Mantid/Framework/DataObjects/test/PeakTest.h
View file @
db4305fe
...
...
@@ -34,6 +34,7 @@ public:
TS_ASSERT_EQUALS
(
p
.
getDetectorID
(),
10000
)
TS_ASSERT_EQUALS
(
p
.
getDetector
()
->
getID
(),
10000
)
TS_ASSERT_EQUALS
(
p
.
getInstrument
(),
inst
)
check_Contributing_Detectors
(
p
,
std
::
vector
<
int
>
(
1
,
10000
));
}
void
test_constructorHKL
()
...
...
@@ -46,6 +47,7 @@ public:
TS_ASSERT_EQUALS
(
p
.
getDetectorID
(),
10000
)
TS_ASSERT_EQUALS
(
p
.
getDetector
()
->
getID
(),
10000
)
TS_ASSERT_EQUALS
(
p
.
getInstrument
(),
inst
)
check_Contributing_Detectors
(
p
,
std
::
vector
<
int
>
(
1
,
10000
));
}
void
test_constructorHKLGon
()
...
...
@@ -67,6 +69,7 @@ public:
TS_ASSERT_EQUALS
(
p
.
getDetector
()
->
getID
(),
10000
)
TS_ASSERT_EQUALS
(
p
.
getInstrument
(),
inst
)
TS_ASSERT_EQUALS
(
p
.
getGoniometerMatrix
(),
mat
);
check_Contributing_Detectors
(
p
,
std
::
vector
<
int
>
(
1
,
10000
));
}
void
test_copyConstructor
()
...
...
@@ -85,6 +88,8 @@ public:
TS_ASSERT_EQUALS
(
p
.
getRunNumber
(),
p2
.
getRunNumber
());
TS_ASSERT_EQUALS
(
p
.
getDetector
(),
p2
.
getDetector
())
TS_ASSERT_EQUALS
(
p
.
getInstrument
(),
p2
.
getInstrument
())
check_Contributing_Detectors
(
p2
,
std
::
vector
<
int
>
(
1
,
10102
));
}
void
test_getValueByColName
()
...
...
@@ -127,6 +132,15 @@ public:
TS_ASSERT_THROWS_ANYTHING
(
p
.
setDetectorID
(
7
)
);
}
void
test_setDetector_Adds_ID_To_Contributing_List_And_Does_Not_Remove_Old_From_Contrib_List
()
{
int
expectedIDs
[
2
]
=
{
10000
,
10001
};
Peak
peak
(
inst
,
expectedIDs
[
0
],
2.0
);
peak
.
setDetectorID
(
expectedIDs
[
1
]);
check_Contributing_Detectors
(
peak
,
std
::
vector
<
int
>
(
expectedIDs
,
expectedIDs
+
2
));
}
void
test_runNumber
()
{
Peak
p
(
inst
,
10000
,
2.0
);
...
...
@@ -292,7 +306,16 @@ public:
TS_ASSERT_EQUALS
(
p2
.
getDetectorID
(),
19999
);
}
private:
void
check_Contributing_Detectors
(
const
Peak
&
peak
,
const
std
::
vector
<
int
>
&
expected
)
{
auto
peakIDs
=
peak
.
getContributingDetIDs
();
for
(
auto
it
=
expected
.
begin
();
it
!=
expected
.
end
();
++
it
)
{
const
int
id
=
*
it
;
TSM_ASSERT_EQUALS
(
"Expected "
+
boost
::
lexical_cast
<
std
::
string
>
(
id
)
+
" in contribution list"
,
1
,
peakIDs
.
count
(
id
))
}
}
};
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment