-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #7351 Extracted Common part of the SofQ codes into separate class
- Loading branch information
Showing
9 changed files
with
170 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/SofQCommon.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef MANTID_ALGORITHMS_SOFQW_COMMON_H_ | ||
#define MANTID_ALGORITHMS_SOFQW_COMMON_H_ | ||
|
||
#include "MantidAPI/Algorithm.h" | ||
#include "MantidGeometry/IDetector.h" | ||
// number of small routines used by all SofQW algorithms intended to provide united user interface to all SofQ algorihtms. | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
struct SofQCommon | ||
{ | ||
|
||
/// E Mode | ||
int m_emode; | ||
/// EFixed has been provided | ||
bool m_efixedGiven; | ||
/// EFixed | ||
double m_efixed; | ||
|
||
SofQCommon():m_emode(0), m_efixedGiven(false), m_efixed(0.0){} | ||
|
||
void initCachedValues(API::MatrixWorkspace_const_sptr workspace, API::Algorithm *const hostAlgorithm); | ||
|
||
/// Get the efixed value for the given detector | ||
double getEFixed(Geometry::IDetector_const_sptr det) const; | ||
}; | ||
|
||
} | ||
} | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include "MantidAlgorithms/SofQCommon.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
/** The procedure analyses emode and efixed properties provided to the algorithm and identify the energy analysis mode and the way the properties are defined | ||
@param workspace :: input workspace which may or may not have incident energy property (Ei) attached to it as the run log | ||
@param hostAlgorithm :: the pointer to SofQ algorithm hosting the base class. This algorithm expects to have EMode and EFixed properties attached to it. | ||
*/ | ||
void SofQCommon::initCachedValues(API::MatrixWorkspace_const_sptr workspace, API::Algorithm *const hostAlgorithm) | ||
{ | ||
// Retrieve the emode & efixed properties | ||
const std::string emode = hostAlgorithm->getProperty("EMode"); | ||
// Convert back to an integer representation | ||
m_emode = 0; | ||
if (emode == "Direct") m_emode=1; | ||
else if (emode == "Indirect") m_emode = 2; | ||
m_efixed = hostAlgorithm->getProperty("EFixed"); | ||
|
||
// Check whether they should have supplied an EFixed value | ||
if( m_emode == 1 ) // Direct | ||
{ | ||
// If GetEi was run then it will have been stored in the workspace, if not the user will need to enter one | ||
if( m_efixed == 0.0 ) | ||
{ | ||
if ( workspace->run().hasProperty("Ei") ) | ||
{ | ||
Kernel::Property *p = workspace->run().getProperty("Ei"); | ||
Kernel::PropertyWithValue<double> *eiProp = dynamic_cast<Kernel::PropertyWithValue<double>*>(p); | ||
if( !eiProp ) throw std::runtime_error("Input workspace contains Ei but its property type is not a double."); | ||
m_efixed = (*eiProp)(); | ||
} | ||
else | ||
{ | ||
throw std::invalid_argument("Input workspace does not contain an EFixed value. Please provide one or run GetEi."); | ||
} | ||
} | ||
else | ||
{ | ||
m_efixedGiven = true; | ||
} | ||
} | ||
else | ||
{ | ||
if( m_efixed != 0.0 ) | ||
{ | ||
m_efixedGiven = true; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
/** | ||
* Return the efixed for this detector. In Direct mode this has to be property set up earlier and in Indirect mode it may be the property of a component | ||
if not specified globally for the instrument. | ||
* @param det A pointer to a detector object | ||
* @return The value of efixed | ||
*/ | ||
double SofQCommon::getEFixed(Geometry::IDetector_const_sptr det) const | ||
{ | ||
double efixed(0.0); | ||
if( m_emode == 1 ) //Direct | ||
{ | ||
efixed = m_efixed; | ||
} | ||
else // Indirect | ||
{ | ||
if( m_efixedGiven ) efixed = m_efixed; // user provided a value | ||
else | ||
{ | ||
std::vector<double> param = det->getNumberParameter("EFixed"); | ||
if( param.empty() ) throw std::runtime_error("Cannot find EFixed parameter for component \"" + det->getName() | ||
+ "\". This is required in indirect mode. Please check the IDF contains these values."); | ||
efixed = param[0]; | ||
} | ||
} | ||
return efixed; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.