Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:mantidproject/mantid into feature…
…/9907_update_idf_schema
- Loading branch information
Showing
53 changed files
with
2,240 additions
and
1,988 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,36 @@ | ||
############################################################################### | ||
# - Attempt to find Qwt libraries and include files. | ||
# QWT_INCLUDE_DIR where to find qwt_plot.h, etc. | ||
# QWT_LIBRARIES libraries to link against | ||
# QWT_FOUND If false, do not try to use Qwt | ||
# QWT_VERSION Sets a string containing the version number parsed from | ||
# qwt_global.h | ||
# Attempt to find Qwt libraries and include files. | ||
# Set | ||
# QWT_INCLUDE_DIR: where to find qwt_plot.h, etc. | ||
# QWT_LIBRARIES: libraries to link against | ||
# QWT_VERSION: a string containing the version number | ||
############################################################################### | ||
|
||
find_path ( QWT_INCLUDE_DIR qwt.h PATHS | ||
/usr/local/include | ||
/usr/include/qwt-qt4 | ||
/usr/include/qwt | ||
/usr/include/qwt5 | ||
/usr/include/qwt5-qt4 | ||
${CMAKE_INCLUDE_PATH}/qwt | ||
) | ||
find_library ( QWT_LIBRARY NAMES qwt-qt4 qwt qwt5-qt4 ) | ||
find_path ( QWT_INCLUDE_DIR qwt.h | ||
PATHS /opt/include /usr/local/include /usr/include ${CMAKE_INCLUDE_PATH} | ||
PATH_SUFFIXES qwt5 qwt5-qt4 qwt-qt4 qwt ) | ||
find_library ( QWT_LIBRARY NAMES qwt5-qt4 qwt-qt4 qwt ) | ||
find_library ( QWT_LIBRARY_DEBUG qwtd ) | ||
|
||
# handle the QUIETLY and REQUIRED arguments and set QWT_FOUND to TRUE if | ||
# all listed variables are TRUE | ||
# in REQUIRED mode: terminate if one of the above find commands failed | ||
include ( FindPackageHandleStandardArgs ) | ||
find_package_handle_standard_args( Qwt DEFAULT_MSG QWT_LIBRARY QWT_INCLUDE_DIR ) | ||
|
||
if ( QWT_INCLUDE_DIR ) | ||
# Look for line in qwt_global.h containing version string | ||
file ( STRINGS ${QWT_INCLUDE_DIR}/qwt_global.h QWT_VERSION | ||
REGEX "^#define[ \t]+QWT_VERSION_STR[ \t]+\"[0-9]+.[0-9]+.[0-9]+\"$" ) | ||
if ( NOT QWT_VERSION ) | ||
message ( WARNING "Unrecognized Qwt version, cannot find QWT_VERSION_STR in qwt_global.h" ) | ||
set ( QWT_VERSION "0.0.0" ) | ||
else() | ||
# Hack off the portion up to and including the first double quote | ||
string( REGEX REPLACE "^#define[ \t]+QWT_VERSION_STR[ \t]+\"" "" QWT_VERSION ${QWT_VERSION} ) | ||
# Hack off the portion from the second double quote to the end of the line | ||
string( REGEX REPLACE "\"$" "" QWT_VERSION ${QWT_VERSION} ) | ||
endif() | ||
|
||
if ( QWT_LIBRARY_DEBUG ) | ||
set( QWT_LIBRARIES optimized ${QWT_LIBRARY} debug ${QWT_LIBRARY_DEBUG} ) | ||
else () | ||
set( QWT_LIBRARIES ${QWT_LIBRARY} ) | ||
endif () | ||
# Parse version string from qwt_global.h | ||
file ( STRINGS ${QWT_INCLUDE_DIR}/qwt_global.h QWT_VERSION | ||
REGEX "^#define[ \t]+QWT_VERSION_STR[ \t]+\"[0-9]+.[0-9]+.[0-9]+\"$" ) | ||
if ( NOT QWT_VERSION ) | ||
message ( FATAL_ERROR "Unrecognized Qwt version (cannot find QWT_VERSION_STR in qwt_global.h)" ) | ||
endif() | ||
# hack off the portion up to and including the first double quote | ||
string( REGEX REPLACE "^#define[ \t]+QWT_VERSION_STR[ \t]+\"" "" QWT_VERSION ${QWT_VERSION} ) | ||
# hack off the portion from the second double quote to the end of the line | ||
string( REGEX REPLACE "\"$" "" QWT_VERSION ${QWT_VERSION} ) | ||
|
||
if ( QWT_LIBRARY_DEBUG ) | ||
set( QWT_LIBRARIES optimized ${QWT_LIBRARY} debug ${QWT_LIBRARY_DEBUG} ) | ||
else () | ||
set( QWT_LIBRARIES ${QWT_LIBRARY} ) | ||
endif () | ||
|
||
mark_as_advanced ( QWT_INCLUDE_DIR QWT_LIBRARY QWT_LIBRARY_DEBUG ) |
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
56 changes: 56 additions & 0 deletions
56
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/LorentzCorrection.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,56 @@ | ||
#ifndef MANTID_ALGORITHMS_LORENTZCORRECTION_H_ | ||
#define MANTID_ALGORITHMS_LORENTZCORRECTION_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
/** LorentzCorrection : Algorithm Performs a lorentz correction (sin(theta)^2)/(wavelength^4) on a MatrixWorkspace in units of wavelength | ||
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport LorentzCorrection : public API::Algorithm | ||
{ | ||
public: | ||
LorentzCorrection(); | ||
virtual ~LorentzCorrection(); | ||
|
||
virtual const std::string name() const; | ||
virtual int version() const; | ||
virtual const std::string category() const; | ||
virtual const std::string summary() const; | ||
|
||
private: | ||
void init(); | ||
void exec(); | ||
|
||
|
||
}; | ||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_ALGORITHMS_LORENTZCORRECTION_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
150 changes: 150 additions & 0 deletions
150
Code/Mantid/Framework/Algorithms/src/LorentzCorrection.cpp
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,150 @@ | ||
#include "MantidAlgorithms/LorentzCorrection.h" | ||
#include "MantidAPI/MatrixWorkspace.h" | ||
#include "MantidAPI/Progress.h" | ||
#include "MantidAPI/WorkspaceValidators.h" | ||
#include "MantidKernel/MultiThreaded.h" | ||
#include <boost/make_shared.hpp> | ||
#include <boost/shared_ptr.hpp> | ||
#include <cmath> | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
using namespace Mantid::Geometry; | ||
using namespace Mantid::Kernel; | ||
using Mantid::API::WorkspaceProperty; | ||
|
||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(LorentzCorrection) | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
LorentzCorrection::LorentzCorrection() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
LorentzCorrection::~LorentzCorrection() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
|
||
/// Algorithm's version for identification. @see Algorithm::version | ||
int LorentzCorrection::version() const | ||
{ | ||
return 1; | ||
} | ||
; | ||
|
||
/// Algorithm's category for identification. @see Algorithm::category | ||
const std::string LorentzCorrection::category() const | ||
{ | ||
return "Crystal"; | ||
} | ||
|
||
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary | ||
const std::string LorentzCorrection::summary() const | ||
{ | ||
return "Performs a white beam Lorentz Correction"; | ||
} | ||
; | ||
|
||
const std::string LorentzCorrection::name() const | ||
{ | ||
return "LorentzCorrection"; | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void LorentzCorrection::init() | ||
{ | ||
|
||
declareProperty( | ||
new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "", Direction::Input, | ||
PropertyMode::Mandatory, boost::make_shared<WorkspaceUnitValidator>("Wavelength")), | ||
"Input workspace to correct in Wavelength."); | ||
declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace", "", Direction::Output), | ||
"An output workspace."); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void LorentzCorrection::exec() | ||
{ | ||
MatrixWorkspace_sptr inWS = this->getProperty("InputWorkspace"); | ||
|
||
auto cloneAlg = this->createChildAlgorithm("CloneWorkspace", 0, 0.1); | ||
cloneAlg->initialize(); | ||
cloneAlg->setProperty("InputWorkspace", inWS); | ||
cloneAlg->execute(); | ||
Workspace_sptr temp = cloneAlg->getProperty("OutputWorkspace"); | ||
MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>(temp); | ||
|
||
const auto numHistos = inWS->getNumberHistograms(); | ||
Progress prog(this, 0, 1, numHistos); | ||
const bool isHist = inWS->isHistogramData(); | ||
|
||
PARALLEL_FOR1(inWS) | ||
for (int64_t i = 0; i < int64_t(numHistos); ++i) | ||
{ | ||
PARALLEL_START_INTERUPT_REGION | ||
|
||
const MantidVec& inY = inWS->readY(i); | ||
const MantidVec& inX = inWS->readX(i); | ||
|
||
MantidVec& outY = outWS->dataY(i); | ||
MantidVec& outE = outWS->dataE(i); | ||
|
||
IDetector_const_sptr detector; | ||
try | ||
{ | ||
detector = inWS->getDetector(i); | ||
} catch (Exception::NotFoundError&) | ||
{ | ||
// Catch if no detector. Next line tests whether this happened - test placed | ||
// outside here because Mac Intel compiler doesn't like 'continue' in a catch | ||
// in an openmp block. | ||
} | ||
// If no detector found, skip onto the next spectrum | ||
if (!detector) | ||
continue; | ||
|
||
const double twoTheta = inWS->detectorTwoTheta(detector); | ||
const double sinTheta = std::sin(twoTheta / 2); | ||
double sinThetaSq = sinTheta * sinTheta; | ||
|
||
for (size_t j = 0; j < inY.size(); ++j) | ||
{ | ||
const double wL = isHist ? (0.5 * (inX[j] + inX[j + 1])) : inX[j]; | ||
if(wL == 0) | ||
{ | ||
std::stringstream buffer; | ||
buffer << "Cannot have zero values Wavelength. At workspace index: " << i; | ||
throw std::runtime_error(buffer.str()); | ||
} | ||
|
||
double weight = sinThetaSq / (wL * wL * wL * wL); | ||
outY[j] *= weight; | ||
outE[j] *= weight; | ||
} | ||
|
||
prog.report(); | ||
|
||
PARALLEL_END_INTERUPT_REGION | ||
} | ||
PARALLEL_CHECK_INTERUPT_REGION | ||
|
||
this->setProperty("OutputWorkspace", outWS); | ||
} | ||
|
||
} // namespace Algorithms | ||
} // namespace Mantid |
Oops, something went wrong.