Skip to content

Commit

Permalink
Refs #11847. Checkpointing progress on building virtual instrument.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed May 28, 2015
1 parent f7d7747 commit ef55256
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
Expand Up @@ -67,6 +67,10 @@ MANTID_GEOMETRY_DLL Geometry::Instrument_sptr createMinimalInstrument(const Mant
const Mantid::Kernel::V3D& samplePos,
const Mantid::Kernel::V3D& detectorPos );

MANTID_GEOMETRY_DLL Geometry::Instrument_sptr createVirtualInstrument(Kernel::V3D sourcePos, Kernel::V3D samplePos,
const std::vector<Kernel::V3D> vecdetpos,
const std::vector<detid_t> vecdetid);

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

Expand Down
39 changes: 39 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Instrument/ComponentHelper.cpp
Expand Up @@ -139,6 +139,45 @@ Geometry::Instrument_sptr createMinimalInstrument(const Mantid::Kernel::V3D& sou
}


Geometry::Instrument_sptr createVirtualInstrument(Kernel::V3D sourcePos, Kernel::V3D samplePos,
const std::vector<Kernel::V3D> vecdetpos,
const std::vector<detid_t> vecdetid)
{
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
size_t numdets = vecdetpos.size();
for (size_t i = 0; i < numdets; ++i)
{
Detector *det = new Detector("point-detector", vecdetid[i] /*detector id*/, NULL);
det->setPos(vecdetpos[i]);
// FIXME - should be cubi... pixel
det->setShape(createSphere(0.01 /*1cm*/, V3D(0,0,0), "1"));
instrument->add(det);
instrument->markAsDetector(det);
}

return instrument;

}


/**
* Create a sphere object
*/
Expand Down
Expand Up @@ -3,6 +3,7 @@
#include "MantidKernel/ArrayProperty.h"
#include "MantidGeometry/Instrument.h"
#include "MantidDataObjects/MDEventFactory.h"
#include "MantidGeometry/Instrument/ComponentHelper.h"

using namespace Mantid::API;
using namespace Mantid::Kernel;
Expand Down Expand Up @@ -40,6 +41,9 @@ void ConvertCWSDExpToMomentum::init() {

declareProperty(new ArrayProperty<double>("SamplePosition"),
"A vector of 3 doubles for position of sample.");

declareProperty(new ArrayProperty<double>("PixelDimension"),
"A vector of 8 doubles to determine a cubic pixel's size.");
}

/**
Expand All @@ -53,6 +57,8 @@ void ConvertCWSDExpToMomentum::exec() {
throw std::runtime_error(errmsg);

// Create output MDEventWorkspace
std::vector<Kernel::V3D> vecDetPos;
std::vector<detid_t> vecDetID;
m_outputWS = createExperimentMDWorkspace();

// Add MDEventWorkspace
Expand All @@ -61,13 +67,16 @@ void ConvertCWSDExpToMomentum::exec() {

API::IMDEventWorkspace_sptr
ConvertCWSDExpToMomentum::createExperimentMDWorkspace() {
// Get detector list
// Get detector list from input table workspace
std::vector<Kernel::V3D> vec_detpos;
std::vector<detid_t> vec_detid;
parseDetectorTable(vec_detpos, vec_detid);

// FIXME - Should set create a solid instrument
Geometry::Instrument_sptr virtualinstrument;
Geometry::Instrument_sptr virtualinstrument = Geometry::ComponentHelper::createVirtualInstrument(m_sourcePos,
m_samplePos,
vec_detpos,
vec_detid);

size_t m_nDimensions = 3;
IMDEventWorkspace_sptr mdws =
Expand All @@ -81,11 +90,11 @@ ConvertCWSDExpToMomentum::createExperimentMDWorkspace() {
vec_ID[1] = "y";
vec_ID[2] = "z";

std::vector<std::string> vec_name(3);
vec_name[0] = "X";
vec_name[1] = "Y";
vec_name[2] = "Z";

std::vector<std::string> dimensionNames(3);
dimensionNames[0] = "Q_sample_x";
dimensionNames[1] = "Q_sample_y";
dimensionNames[2] = "Q_sample_z";
Mantid::Kernel::SpecialCoordinateSystem coordinateSystem = Mantid::Kernel::QSample;
// Add dimensions
for (size_t i = 0; i < m_nDimensions; ++i) {
std::string id = vec_ID[i];
Expand Down Expand Up @@ -113,6 +122,8 @@ ConvertCWSDExpToMomentum::createExperimentMDWorkspace() {

// FIXME - Add instrument?

mdws->setCoordinateSystem(coordinateSystem);

return mdws;
}

Expand Down

0 comments on commit ef55256

Please sign in to comment.