Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from mantidproject/feature/11056_create_peak_hkl
Corrupted state DataObject::Peak
- Loading branch information
Showing
33 changed files
with
719 additions
and
75 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
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
56 changes: 56 additions & 0 deletions
56
Code/Mantid/Framework/Crystal/inc/MantidCrystal/AddPeakHKL.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_CRYSTAL_ADDPEAKHKL_H_ | ||
#define MANTID_CRYSTAL_ADDPEAKHKL_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Crystal | ||
{ | ||
|
||
/** AddPeakHKL : Algorithm to add a peaks to a PeaksWorkspace in the HKL frame | ||
Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source | ||
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 AddPeakHKL : public API::Algorithm | ||
{ | ||
public: | ||
AddPeakHKL(); | ||
virtual ~AddPeakHKL(); | ||
|
||
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 Crystal | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_CRYSTAL_ADDPEAKHKL_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,74 @@ | ||
#include "MantidCrystal/AddPeakHKL.h" | ||
#include "MantidAPI/IPeaksWorkspace.h" | ||
#include "MantidAPI/IPeak.h" | ||
#include "MantidKernel/ArrayProperty.h" | ||
#include "MantidKernel/ArrayLengthValidator.h" | ||
#include "MantidKernel/V3D.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Crystal | ||
{ | ||
|
||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
|
||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(AddPeakHKL) | ||
|
||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
AddPeakHKL::AddPeakHKL() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
AddPeakHKL::~AddPeakHKL() | ||
{ | ||
} | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
|
||
/// Algorithms name for identification. @see Algorithm::name | ||
const std::string AddPeakHKL::name() const { return "AddPeakHKL"; } | ||
|
||
/// Algorithm's version for identification. @see Algorithm::version | ||
int AddPeakHKL::version() const { return 1;}; | ||
|
||
/// Algorithm's category for identification. @see Algorithm::category | ||
const std::string AddPeakHKL::category() const { return "Crystal";} | ||
|
||
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary | ||
const std::string AddPeakHKL::summary() const { return "Add a peak in the hkl frame";}; | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void AddPeakHKL::init() | ||
{ | ||
declareProperty(new WorkspaceProperty<Mantid::API::IPeaksWorkspace>("Workspace","",Direction::InOut), "An input workspace."); | ||
declareProperty(new ArrayProperty<double>("HKL", boost::make_shared<ArrayLengthValidator<double> > (3)), "HKL point to add"); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void AddPeakHKL::exec() | ||
{ | ||
IPeaksWorkspace_sptr peakWS = this->getProperty("Workspace"); | ||
const std::vector<double> hklValue = this->getProperty("HKL"); | ||
IPeak * peak = peakWS->createPeakHKL(V3D(hklValue[0], hklValue[1], hklValue[2])); | ||
peakWS->addPeak(*peak); | ||
delete peak; | ||
} | ||
|
||
|
||
|
||
} // namespace Crystal | ||
} // 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
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,112 @@ | ||
#ifndef MANTID_CRYSTAL_ADDPEAKHKLTEST_H_ | ||
#define MANTID_CRYSTAL_ADDPEAKHKLTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
#include "MantidCrystal/AddPeakHKL.h" | ||
#include "MantidKernel/V3D.h" | ||
#include "MantidAPI/AnalysisDataService.h" | ||
#include "MantidDataObjects/PeaksWorkspace.h" | ||
#include "MantidGeometry/Crystal/OrientedLattice.h" | ||
#include "MantidTestHelpers/ComponentCreationHelper.h" | ||
|
||
using Mantid::Crystal::AddPeakHKL; | ||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
using namespace Mantid::DataObjects; | ||
|
||
class AddPeakHKLTest : 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 AddPeakHKLTest *createSuite() { return new AddPeakHKLTest(); } | ||
static void destroySuite( AddPeakHKLTest *suite ) { delete suite; } | ||
|
||
|
||
void test_Init() | ||
{ | ||
AddPeakHKL alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
} | ||
|
||
void test_hkl_validation() | ||
{ | ||
AddPeakHKL alg; | ||
alg.initialize(); | ||
std::vector<double> hkl_bad(4); // Too big! | ||
TS_ASSERT_THROWS( alg.setProperty("HKL", hkl_bad), std::invalid_argument& ); | ||
|
||
std::vector<double> hkl_good(3, 0); // Right size. | ||
TS_ASSERT_THROWS_NOTHING( alg.setProperty("HKL", hkl_good) ); | ||
} | ||
|
||
|
||
void test_exec() | ||
{ | ||
// Create simple fictional instrument | ||
const V3D source(0,0,0); | ||
const V3D sample(15, 0, 0); | ||
const V3D detectorPos(20, 5, 0); | ||
const V3D beam1 = sample - source; | ||
const V3D beam2 = detectorPos - sample; | ||
auto minimalInstrument = ComponentCreationHelper::createMinimalInstrument( source, sample, detectorPos ); | ||
|
||
// Derive distances and angles | ||
const double l1 = beam1.norm(); | ||
const double l2 = beam2.norm(); | ||
const V3D qLabDir = (beam1/l1) - (beam2/l2); | ||
|
||
const double microSecsInSec = 1e6; | ||
|
||
// Derive QLab for diffraction | ||
const double wavenumber_in_angstrom_times_tof_in_microsec = | ||
(Mantid::PhysicalConstants::NeutronMass * (l1 + l2) * 1e-10 * microSecsInSec) / | ||
Mantid::PhysicalConstants::h_bar; | ||
V3D qLab = qLabDir * wavenumber_in_angstrom_times_tof_in_microsec; | ||
|
||
Mantid::Geometry::OrientedLattice orientedLattice(1, 1, 1, 90, 90, 90); // U is identity, real and reciprocal lattice vectors are identical. | ||
Mantid::Geometry::Goniometer goniometer; // identity | ||
V3D hkl = qLab / (2 * M_PI); // Given our settings above, this is the simplified relationship between qLab and hkl. | ||
|
||
// Now create a peaks workspace around the simple fictional instrument | ||
PeaksWorkspace_sptr ws = boost::make_shared<PeaksWorkspace>(); | ||
ws->setInstrument(minimalInstrument); | ||
ws->mutableSample().setOrientedLattice(&orientedLattice); | ||
ws->mutableRun().setGoniometer(goniometer, false); | ||
|
||
AddPeakHKL alg; | ||
alg.setChild(true); | ||
alg.initialize(); | ||
std::vector<double> hklVec; | ||
hklVec.push_back(hkl.X()); | ||
hklVec.push_back(hkl.Y()); | ||
hklVec.push_back(hkl.Z()); | ||
alg.setProperty("HKL", hklVec); | ||
alg.setProperty("Workspace", ws); | ||
alg.execute(); | ||
IPeaksWorkspace_sptr ws_out = alg.getProperty("Workspace"); | ||
|
||
// Get the peak just added. | ||
const IPeak& peak =ws_out->getPeak(0); | ||
|
||
/* | ||
Now we check we have made a self - consistent peak | ||
*/ | ||
TSM_ASSERT_EQUALS("New peak should have HKL we demanded.", hkl, peak.getHKL()); | ||
TSM_ASSERT_EQUALS("New peak should have QLab we expected.", qLab, peak.getQLabFrame()); | ||
TSM_ASSERT_EQUALS("QSample and QLab should be identical given the identity goniometer settings.", peak.getQLabFrame(), peak.getQSampleFrame()); | ||
auto detector = peak.getDetector(); | ||
TSM_ASSERT("No detector", detector); | ||
TSM_ASSERT_EQUALS("This detector id does not match what we expect from the instrument definition", 1, detector->getID()); | ||
TSM_ASSERT_EQUALS("Thie detector position is wrong", detectorPos, detector->getPos()); | ||
TSM_ASSERT_EQUALS("Goniometer has not been set properly", goniometer.getR(), peak.getGoniometerMatrix()); | ||
|
||
} | ||
|
||
|
||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_CRYSTAL_ADDPEAKHKLTEST_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
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.