Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/10169_vesuvio_mscorr'
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Oct 31, 2014
2 parents f617737 + 6e4da70 commit a8c3ff4
Show file tree
Hide file tree
Showing 30 changed files with 2,171 additions and 180 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/CMakeLists.txt
Expand Up @@ -105,6 +105,7 @@ set ( SRC_FILES
src/Run.cpp
src/Sample.cpp
src/SampleEnvironment.cpp
src/SampleShapeValidator.cpp
src/ScopedWorkspace.cpp
src/ScriptBuilder.cpp
src/ScriptRepository.cpp
Expand Down Expand Up @@ -264,6 +265,7 @@ set ( INC_FILES
inc/MantidAPI/Run.h
inc/MantidAPI/Sample.h
inc/MantidAPI/SampleEnvironment.h
inc/MantidAPI/SampleShapeValidator.h
inc/MantidAPI/ScopedWorkspace.h
inc/MantidAPI/ScriptBuilder.h
inc/MantidAPI/ScriptRepository.h
Expand Down Expand Up @@ -355,6 +357,7 @@ set ( TEST_FILES
PropertyNexusTest.h
RunTest.h
SampleEnvironmentTest.h
SampleShapeValidatorTest.h
SampleTest.h
ScopedWorkspaceTest.h
ScriptBuilderTest.h
Expand Down
52 changes: 52 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/SampleShapeValidator.h
@@ -0,0 +1,52 @@
#ifndef MANTID_API_SAMPLESHAPEVALIDATOR_H_
#define MANTID_API_SAMPLESHAPEVALIDATOR_H_

#include "MantidAPI/DllConfig.h"
#include "MantidAPI/ExperimentInfo.h"

#include "MantidKernel/TypedValidator.h"

namespace Mantid
{
namespace API
{

/**
Verify that a workspace has valid sample shape.
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 MANTID_API_DLL SampleShapeValidator :
public Kernel::TypedValidator<boost::shared_ptr<ExperimentInfo> >
{
public:
std::string getType() const;
Kernel::IValidator_sptr clone() const;

private:
std::string checkValidity(const boost::shared_ptr<ExperimentInfo>& value) const;
};

} // namespace API
} // namespace Mantid

#endif /* MANTID_API_SAMPLESHAPEVALIDATOR_H_ */
50 changes: 50 additions & 0 deletions Code/Mantid/Framework/API/src/SampleShapeValidator.cpp
@@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "MantidAPI/SampleShapeValidator.h"
#include "MantidGeometry/Objects/Object.h"

namespace Mantid
{
namespace API
{
//-----------------------------------------------------------------------------
// Public methods
//-----------------------------------------------------------------------------

/// @return A string identifier for the type of validator
std::string SampleShapeValidator::getType() const
{
return "SampleShape";
}

/// @return A copy of the validator as a new object
Kernel::IValidator_sptr SampleShapeValidator::clone() const
{
return boost::make_shared<SampleShapeValidator>();
}

//-----------------------------------------------------------------------------
// Private methods
//-----------------------------------------------------------------------------

/**
* Checks that the workspace has a valid sample shape defined
* @param value :: The workspace to test
* @return A user level description if a problem exists or ""
*/
std::string SampleShapeValidator::checkValidity( const boost::shared_ptr<ExperimentInfo>& value ) const
{
const auto & sampleShape = value->sample().getShape();
if(sampleShape.hasValidShape())
{
return "";
}
else
{
return "Invalid or no shape defined for sample";
}
}

} // namespace API
} // namespace Mantid
46 changes: 46 additions & 0 deletions Code/Mantid/Framework/API/test/SampleShapeValidatorTest.h
@@ -0,0 +1,46 @@
#ifndef MANTID_API_SAMPLESHAPEVALIDATORTEST_H_
#define MANTID_API_SAMPLESHAPEVALIDATORTEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidAPI/SampleShapeValidator.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidTestHelpers/FakeObjects.h"

#include "boost/make_shared.hpp"

using Mantid::API::SampleShapeValidator;

class SampleShapeValidatorTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static SampleShapeValidatorTest *createSuite() { return new SampleShapeValidatorTest(); }
static void destroySuite( SampleShapeValidatorTest *suite ) { delete suite; }

void test_validator_passes_for_workspace_with_defined_sample_shape()
{
auto fakeWS = boost::make_shared<WorkspaceTester>();
// Add a sample shape
auto sphere = ComponentCreationHelper::createSphere(1.0, V3D(), "sphere");
fakeWS->mutableSample().setShape(*sphere);

auto sampleValidator = boost::make_shared<SampleShapeValidator>();
TS_ASSERT_EQUALS( sampleValidator->isValid(fakeWS), "" );
}

void test_validator_throws_error_for_workspace_without_shape()
{
auto fakeWS = boost::make_shared<WorkspaceTester>();

auto sampleValidator = boost::make_shared<SampleShapeValidator>();
TS_ASSERT_EQUALS( sampleValidator->isValid(fakeWS),
"Invalid or no shape defined for sample" );
}


};


#endif /* MANTID_API_SAMPLESHAPEVALIDATORTEST_H_ */
9 changes: 7 additions & 2 deletions Code/Mantid/Framework/CurveFitting/CMakeLists.txt
Expand Up @@ -12,6 +12,7 @@ set ( SRC_FILES
src/Bk2BkExpConvPV.cpp
src/BoundaryConstraint.cpp
src/CalculateGammaBackground.cpp
src/CalculateMSVesuvio.cpp
src/Chebyshev.cpp
src/ComptonPeakProfile.cpp
src/ComptonProfile.cpp
Expand Down Expand Up @@ -56,6 +57,7 @@ set ( SRC_FILES
src/LogNormal.cpp
src/Lorentzian.cpp
src/Lorentzian1D.cpp
src/MSVesuvioHelpers.cpp
src/MultiDomainCreator.cpp
src/MuonFInteraction.cpp
src/NeutronBk2BkExpConvPVoigt.cpp
Expand Down Expand Up @@ -99,7 +101,7 @@ set ( SRC_FILES
src/FakeMinimizer.cpp

)

set ( SRC_UNITY_IGNORE_FILES src/Fit1D.cpp src/GSLFunctions.cpp )

set ( INC_FILES
Expand All @@ -117,6 +119,7 @@ set ( INC_FILES
inc/MantidCurveFitting/Bk2BkExpConvPV.h
inc/MantidCurveFitting/BoundaryConstraint.h
inc/MantidCurveFitting/CalculateGammaBackground.h
inc/MantidCurveFitting/CalculateMSVesuvio.h
inc/MantidCurveFitting/Chebyshev.h
inc/MantidCurveFitting/ComptonPeakProfile.h
inc/MantidCurveFitting/ComptonProfile.h
Expand Down Expand Up @@ -165,6 +168,7 @@ set ( INC_FILES
inc/MantidCurveFitting/LogNormal.h
inc/MantidCurveFitting/Lorentzian.h
inc/MantidCurveFitting/Lorentzian1D.h
inc/MantidCurveFitting/MSVesuvioHelpers.h
inc/MantidCurveFitting/MultiDomainCreator.h
inc/MantidCurveFitting/MuonFInteraction.h
inc/MantidCurveFitting/NeutronBk2BkExpConvPVoigt.h
Expand Down Expand Up @@ -206,7 +210,7 @@ set ( INC_FILES
inc/MantidCurveFitting/VesuvioResolution.h
inc/MantidCurveFitting/Voigt.h
)

set ( TEST_FILES
# ChebyshevPolynomialBackgroundTest.h
# RefinePowderInstrumentParametersTest.h
Expand All @@ -220,6 +224,7 @@ set ( TEST_FILES
Bk2BkExpConvPVTest.h
BoundaryConstraintTest.h
CalculateGammaBackgroundTest.h
CalculateMSVesuvioTest.h
ChebyshevTest.h
CompositeFunctionTest.h
ComptonPeakProfileTest.h
Expand Down
@@ -0,0 +1,148 @@
#ifndef MANTID_CURVEFITTING_CALCULATEMSVESUVIO_H_
#define MANTID_CURVEFITTING_CALCULATEMSVESUVIO_H_
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"
#include "MantidKernel/V3D.h"

namespace Mantid
{
namespace CurveFitting
{
//-----------------------------------------------------------------------------
// CurveFitting forward declarations
//-----------------------------------------------------------------------------
struct DetectorParams;
struct ResolutionParams;
namespace MSVesuvioHelper
{
class RandomNumberGenerator;
struct Simulation;
struct SimulationWithErrors;
}

/**
Calculates the multiple scattering & total scattering contributions
for a flat-plate or cylindrical sample.
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 CalculateMSVesuvio : public API::Algorithm
{
private:
// Holds date on the compton scattering properties of an atom
struct ComptonNeutronAtom
{
ComptonNeutronAtom()
: mass(-1.0), sclength(-1.0), profile(-1.0) {}
double mass; // in amu
double sclength; // 4pi/xsec
double profile; // s.d of J(y)
};
// Holds data about sample as a whole.
struct SampleComptonProperties
{
SampleComptonProperties(const int nprops)
: atoms(nprops), density(-1.0), totalxsec(-1.0),
mu(-1.0) {}

std::vector<ComptonNeutronAtom> atoms;
double density; // g/cm^3
double totalxsec; // total free-scattering cross section
double mu; // attenuation factor (1/m)
};

public:
CalculateMSVesuvio();
~CalculateMSVesuvio();

/// @copydoc Algorithm::name
virtual const std::string name() const { return "CalculateMSVesuvio"; }
/// @copydoc Algorithm::version
virtual int version() const { return 1; }
/// @copydoc Algorithm::category
virtual const std::string category() const { return "ISIS"; }
/// @copydoc Algorithm::summary
virtual const std::string summary() const
{
return "Calculates the contributions of multiple scattering "
"on a flat plate sample for VESUVIO";
}

private:
void init();
void exec();

void cacheInputs();
void calculateMS(const size_t wsIndex, API::ISpectrum & totalsc,
API::ISpectrum & multsc) const;
void simulate(const DetectorParams & detpar,
const ResolutionParams &respar,
MSVesuvioHelper::Simulation & simulCounts) const;
void assignToOutput(const MSVesuvioHelper::SimulationWithErrors & avgCounts,
API::ISpectrum & totalsc, API::ISpectrum & multsc) const;
double calculateCounts(const DetectorParams & detpar,
const ResolutionParams &respar,
MSVesuvioHelper::Simulation & simulation) const;

// single-event helpers
Kernel::V3D generateSrcPos(const double l1) const;
double generateE0(const double l1, const double t2, double &weight) const;
double generateTOF(const double gaussTOF, const double dtof, const double dl1) const;
bool generateScatter(const Kernel::V3D &startPos, const Kernel::V3D &direc, double &weight,
Kernel::V3D &scatterPt) const;
std::pair<double, double> calculateE1Range(const double theta, const double en0) const;
double partialDiffXSec(const double en0, const double en1, const double theta) const;
Kernel::V3D generateDetectorPos(const Kernel::V3D & nominalPos, const double energy,
const Kernel::V3D &scatterPt,
const Kernel::V3D & direcBeforeSc,
double &scang, double &distToExit) const;
double generateE1(const double angle, const double e1nom, const double e1res) const;

// Member Variables
MSVesuvioHelper::RandomNumberGenerator *m_randgen; // random number generator

size_t m_acrossIdx, m_upIdx, m_beamIdx; // indices of each direction
Kernel::V3D m_beamDir; // Directional vector for beam
double m_srcR2; // beam penumbra radius (m)
double m_halfSampleHeight, m_halfSampleWidth, m_halfSampleThick; // (m)
double m_maxWidthSampleFrame; // Maximum width in sample frame (m)
Geometry::Object const *m_sampleShape; // sample shape
SampleComptonProperties *m_sampleProps; // description of sample properties
double m_detHeight, m_detWidth, m_detThick; // (m)
double m_tmin, m_tmax, m_delt; // min, max & dt TOF value
double m_foilRes; // resolution in energy of foil

size_t m_nscatters; // highest order of scattering to generate
size_t m_nruns; // number of runs per spectrum
size_t m_nevents; // number of single events per run

API::Progress *m_progress;
API::MatrixWorkspace_sptr m_inputWS;
};

} // namespace CurveFitting
} // namespace Mantid

#endif /* MANTID_CURVEFITTING_CALCULATEMSVESUVIO_H_ */
Expand Up @@ -14,6 +14,7 @@ namespace CurveFitting
{
double l1; ///< source-sample distance in metres
double l2; ///< sample-detector distance in metres
Kernel::V3D pos; ///< Full 3D position
double theta; ///< scattering angle in radians
double t0; ///< time delay in seconds
double efixed; ///< final energy
Expand Down

0 comments on commit a8c3ff4

Please sign in to comment.