Skip to content

Commit

Permalink
Starting to implement the algorithm. Refs #11847.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed May 26, 2015
1 parent 8157393 commit 72221a1
Show file tree
Hide file tree
Showing 7 changed files with 428 additions and 1 deletion.
Expand Up @@ -2,6 +2,7 @@
#define MANTID_GEOMETRY_COMPONENTHELPERS_H_

#include "MantidGeometry/DllConfig.h"
#include "MantidGeometry/Instrument.h"

namespace Mantid {
namespace Kernel {
Expand Down Expand Up @@ -61,6 +62,17 @@ MANTID_GEOMETRY_DLL void rotateComponent(const IComponent &comp,
ParameterMap &pmap,
const Kernel::Quat &rot,
const TransformType positionType);

MANTID_GEOMETRY_DLL Geometry::Instrument_sptr createMinimalInstrument(const Mantid::Kernel::V3D& sourcePos,
const Mantid::Kernel::V3D& samplePos,
const Mantid::Kernel::V3D& detectorPos );

MANTID_GEOMETRY_DLL Object_sptr createSphere(double radius, const Kernel::V3D &centre,
const std::string &id);

MANTID_GEOMETRY_DLL std::string sphereXML(double radius, const Kernel::V3D &centre, const std::string &id) ;


}
} // namespace Geometry
} // namespace Mantid
Expand Down
69 changes: 69 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Instrument/ComponentHelper.cpp
Expand Up @@ -4,8 +4,12 @@
#include "MantidGeometry/Instrument/ComponentHelper.h"
#include "MantidGeometry/Instrument/ParameterMap.h"
#include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"
#include "MantidGeometry/Objects/ShapeFactory.h"
#include "MantidGeometry/Instrument/Detector.h"

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

namespace Mantid {
namespace Geometry {
Expand Down Expand Up @@ -92,6 +96,71 @@ void rotateComponent(const IComponent &comp, ParameterMap &pmap,
pmap.addQuat(comp.getComponentID(), "rot", newRot);
}


/**
* createOneDetectorInstrument, creates the most simple possible definition of an instrument in which we can extract a valid L1 and L2 distance for unit calculations.
*
* Beam direction is along X,
* Up direction is Y
*
* @param sourcePos : V3D position
* @param samplePos : V3D sample position
* @param detectorPos : V3D detector position
* @return Instrument generated.
*/
Geometry::Instrument_sptr createMinimalInstrument(const Mantid::Kernel::V3D& sourcePos, const Mantid::Kernel::V3D& samplePos, const Mantid::Kernel::V3D& detectorPos )
{
Instrument_sptr instrument = boost::make_shared<Instrument>();
instrument->setReferenceFrame(
boost::make_shared<ReferenceFrame>(Mantid::Geometry::Y /*up*/, Mantid::Geometry::X /*along*/, Left, "0,0,0"));

// A source
ObjComponent *source = new ObjComponent("source");
source->setPos(sourcePos);
source->setShape(createSphere(0.01 /*1cm*/, V3D(0,0,0), "1"));
instrument->add(source);
instrument->markAsSource(source);

// A sample
ObjComponent *sample = new ObjComponent("some-surface-holder");
sample->setPos(samplePos);
sample->setShape(createSphere(0.01 /*1cm*/, V3D(0,0,0), "1"));
instrument->add(sample);
instrument->markAsSamplePos(sample);

// A detector
Detector *det = new Detector("point-detector", 1 /*detector id*/, NULL);
det->setPos(detectorPos);
det->setShape(createSphere(0.01 /*1cm*/, V3D(0,0,0), "1"));
instrument->add(det);
instrument->markAsDetector(det);

return instrument;
}


/**
* Create a sphere object
*/
Object_sptr createSphere(double radius, const V3D &centre,
const std::string &id) {
ShapeFactory shapeMaker;
return shapeMaker.createShape(sphereXML(radius, centre, id));
}

/**
* Return the XML for a sphere.
*/
std::string sphereXML(double radius, const Kernel::V3D &centre, const std::string &id) {
std::ostringstream xml;
xml << "<sphere id=\"" << id << "\">"
<< "<centre x=\"" << centre.X() << "\" y=\"" << centre.Y() << "\" z=\""
<< centre.Z() << "\" />"
<< "<radius val=\"" << radius << "\" />"
<< "</sphere>";
return xml.str();
}

} // namespace ComponentHelper
}
} // namespace Mantid::Geometry
5 changes: 4 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Expand Up @@ -19,6 +19,7 @@ set ( SRC_FILES
src/ConvToMDHistoWS.cpp
src/ConvToMDSelector.cpp
src/ConvertCWPDMDToSpectra.cpp
src/ConvertCWSDExpToMomentum.cpp
src/ConvertMDHistoToMatrixWorkspace.cpp
src/ConvertSpiceDataToRealSpace.cpp
src/ConvertToDetectorFaceMD.cpp
Expand Down Expand Up @@ -136,6 +137,7 @@ set ( INC_FILES
inc/MantidMDAlgorithms/CompareMDWorkspaces.h
inc/MantidMDAlgorithms/ConvToMDBase.h
inc/MantidMDAlgorithms/ConvertCWPDMDToSpectra.h
inc/MantidMDAlgorithms/ConvertCWSDExpToMomentum.h
inc/MantidMDAlgorithms/ConvertMDHistoToMatrixWorkspace.h
inc/MantidMDAlgorithms/ConvertSpiceDataToRealSpace.h
inc/MantidMDAlgorithms/ConvertToDetectorFaceMD.h
Expand Down Expand Up @@ -252,6 +254,7 @@ set ( TEST_FILES
CloneMDWorkspaceTest.h
CompareMDWorkspacesTest.h
ConvertCWPDMDToSpectraTest.h
ConvertCWSDExpToMomentumTest.h
ConvertEventsToMDTest.h
ConvertMDHistoToMatrixWorkspaceTest.h
ConvertSpiceDataToRealSpaceTest.h
Expand Down Expand Up @@ -321,8 +324,8 @@ set ( TEST_FILES
ReflectometryTransformQxQzTest.h
ResolutionConvolvedCrossSectionTest.h
SaveIsawQvectorTest.h
SaveMDTest.h
SaveMD2Test.h
SaveMDTest.h
SaveZODSTest.h
SetMDUsingMaskTest.h
SimulateResolutionConvolvedModelTest.h
Expand Down
@@ -0,0 +1,41 @@
#ifndef MANTID_MDALGORITHMS_CONVERTCWSDEXPTOMOMENTUM_H_
#define MANTID_MDALGORITHMS_CONVERTCWSDEXPTOMOMENTUM_H_

#include "MantidKernel/System.h"

namespace Mantid {
namespace MDAlgorithms {

/** ConvertCWSDExpToMomentum : TODO: DESCRIPTION
Copyright &copy; 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 ConvertCWSDExpToMomentum {
public:
ConvertCWSDExpToMomentum();
virtual ~ConvertCWSDExpToMomentum();
};

} // namespace MDAlgorithms
} // namespace Mantid

#endif /* MANTID_MDALGORITHMS_CONVERTCWSDEXPTOMOMENTUM_H_ */
@@ -0,0 +1,17 @@
#include "MantidMDAlgorithms/ConvertCWSDExpToMomentum.h"

namespace Mantid {
namespace MDAlgorithms {

//----------------------------------------------------------------------------------------------
/** Constructor
*/
ConvertCWSDExpToMomentum::ConvertCWSDExpToMomentum() {}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
ConvertCWSDExpToMomentum::~ConvertCWSDExpToMomentum() {}

} // namespace MDAlgorithms
} // namespace Mantid
@@ -0,0 +1,28 @@
#ifndef MANTID_MDALGORITHMS_CONVERTCWSDEXPTOMOMENTUMTEST_H_
#define MANTID_MDALGORITHMS_CONVERTCWSDEXPTOMOMENTUMTEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidMDAlgorithms/ConvertCWSDExpToMomentum.h"

using Mantid::MDAlgorithms::ConvertCWSDExpToMomentum;
using namespace Mantid::API;

class ConvertCWSDExpToMomentumTest : 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 ConvertCWSDExpToMomentumTest *createSuite() { return new ConvertCWSDExpToMomentumTest(); }
static void destroySuite( ConvertCWSDExpToMomentumTest *suite ) { delete suite; }


void test_Something()
{
TSM_ASSERT( "You forgot to write a test!", 0);
}


};


#endif /* MANTID_MDALGORITHMS_CONVERTCWSDEXPTOMOMENTUMTEST_H_ */

0 comments on commit 72221a1

Please sign in to comment.