Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/10169_vesuvio_mscorr'
- Loading branch information
Showing
30 changed files
with
2,171 additions
and
180 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
52 changes: 52 additions & 0 deletions
52
Code/Mantid/Framework/API/inc/MantidAPI/SampleShapeValidator.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,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_ */ |
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,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 |
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,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_ */ |
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
148 changes: 148 additions & 0 deletions
148
Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/CalculateMSVesuvio.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,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 © 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_ */ |
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.