Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mantidproject/mantid into feature…
Browse files Browse the repository at this point in the history
…/9907_update_idf_schema
  • Loading branch information
Anders-Markvardsen committed Sep 16, 2014
2 parents 650e4f3 + 99173b4 commit 01af8be
Show file tree
Hide file tree
Showing 53 changed files with 2,240 additions and 1,988 deletions.
61 changes: 25 additions & 36 deletions Code/Mantid/Build/CMake/FindQwt.cmake
@@ -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 )
31 changes: 29 additions & 2 deletions Code/Mantid/Framework/API/src/NumericAxis.cpp
Expand Up @@ -5,7 +5,13 @@
#include "MantidKernel/Exception.h"
#include "MantidKernel/VectorHelper.h"

#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>

#include "MantidKernel/Logger.h"
namespace
{
Mantid::Kernel::Logger g_log("NumericAxis");
}

namespace Mantid
{
Expand Down Expand Up @@ -157,7 +163,28 @@ bool NumericAxis::operator==(const Axis& axis2) const
*/
std::string NumericAxis::label(const std::size_t& index)const
{
return boost::lexical_cast<std::string>((*this)(index));
std::string numberLabel = boost::str(boost::format("%.13f") % (*this)(index));

// Remove all zeros up to the decimal place or a non zero value
auto it = numberLabel.end() - 1;
for(; it != numberLabel.begin(); --it)
{
if(*it == '0')
{
numberLabel.erase(it);
}
else if(*it == '.')
{
numberLabel.erase(it);
break;
}
else
{
break;
}
}

return numberLabel;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Expand Up @@ -134,6 +134,7 @@ set ( SRC_FILES
src/InterpolatingRebin.cpp
src/InvertMask.cpp
src/Logarithm.cpp
src/LorentzCorrection.cpp
src/MaskBins.cpp
src/MaskBinsFromTable.cpp
src/MaskDetectorsIf.cpp
Expand Down Expand Up @@ -379,6 +380,7 @@ set ( INC_FILES
inc/MantidAlgorithms/InterpolatingRebin.h
inc/MantidAlgorithms/InvertMask.h
inc/MantidAlgorithms/Logarithm.h
inc/MantidAlgorithms/LorentzCorrection.h
inc/MantidAlgorithms/MaskBins.h
inc/MantidAlgorithms/MaskBinsFromTable.h
inc/MantidAlgorithms/MaskDetectorsIf.h
Expand Down Expand Up @@ -625,6 +627,7 @@ set ( TEST_FILES
InterpolatingRebinTest.h
InvertMaskTest.h
LogarithmTest.h
LorentzCorrectionTest.h
MaskBinsFromTableTest.h
MaskBinsTest.h
MaxMinTest.h
Expand Down
@@ -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 &copy; 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_ */
Expand Up @@ -11,14 +11,14 @@ namespace Mantid
{
namespace Algorithms
{
/** Normalises a 2D workspace by a specified monitor spectrum. By default ,the
normalisation is done bin-by-bin following this formula:
/** Normalizes a 2D workspace by a specified monitor spectrum. By default ,the
normalization is done bin-by-bin following this formula:
Norm(s_i)=(s_i/m_i)*Dlam_i*Sum(m_i)/Sum(Dlam_i)
where s_i is the signal in bin i, m_i the count in the corresponding monitor bin,
Dlam_i the width of the bin, Sum(m_i) is the integrated monitor count and
Sum(Dlam_i) the sum of all bin widths (the full range).
Optionally, can instead normalise by the integrated monitor count over a specified
Optionally, can instead normalize by the integrated monitor count over a specified
range in X. In this case all bins in all spectra will simply be divided by this
integrated count. No bin width correction takes place in this case.
Expand All @@ -30,12 +30,12 @@ namespace Algorithms
<LI> InputWorkspace - The name of the input workspace. Must be a histogram
and not a distribution.</LI>
<LI> OutputWorkspace - The name of the output workspace. </LI>
<LI> MonitorSpectrum - The spectrum number for the monitor to normalise with. </LI>
<LI> MonitorSpectrum - The spectrum number for the monitor to normalize with. </LI>
<LI> MonitorWorkspace - A workspace containing the monitor spectrum. </LI>
</UL>
Optional Properties:
These should be set to normalise by an integrated monitor count over the range given
These should be set to normalize by an integrated monitor count over the range given
<UL>
<LI> IntegrationRangeMin - The lower bound of the range to use. </LI>
<LI> IntegrationRangeMax - The upper bound of the range to use. </LI>
Expand Down Expand Up @@ -70,7 +70,7 @@ class DLLExport NormaliseToMonitor : public API::Algorithm
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "NormaliseToMonitor"; }
///Summary of algorithms purpose
virtual const std::string summary() const {return "Normalises a 2D workspace by a specified spectrum, spectrum, described by a monitor ID or spectrun provided in a separate worskspace. ";}
virtual const std::string summary() const {return "Normalizes a 2D workspace by a specified spectrum, spectrum, described by a monitor ID or spectrun provided in a separate worskspace. ";}

/// Algorithm's version for identification overriding a virtual method
virtual int version() const { return 1; }
Expand Down
150 changes: 150 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/LorentzCorrection.cpp
@@ -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

0 comments on commit 01af8be

Please sign in to comment.