Commit d0a46602 authored by Lynch, Vickie's avatar Lynch, Vickie
Browse files

Refs #10254 mask instrument of peaks workspace

parent 3e2d956e
......@@ -7,6 +7,7 @@
#include "MantidAPI/Algorithm.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/MaskWorkspace.h"
#include "MantidDataObjects/PeaksWorkspace.h"
namespace Mantid
{
......@@ -70,6 +71,7 @@ private:
// Implement abstract Algorithm methods
void init();
void exec();
void execPeaks(DataObjects::PeaksWorkspace_sptr WS);
void fillIndexListFromSpectra(std::vector<size_t>& indexList, const std::vector<specid_t>& spectraList,
const API::MatrixWorkspace_sptr WS);
void appendToIndexListFromWS(std::vector<size_t>& indexList, const API::MatrixWorkspace_sptr maskedWorkspace);
......
......@@ -21,6 +21,7 @@ DECLARE_ALGORITHM(MaskDetectors)
using namespace Kernel;
using namespace API;
using namespace DataObjects;
using Geometry::Instrument_const_sptr;
using Geometry::IDetector_const_sptr;
using namespace DataObjects;
......@@ -37,7 +38,7 @@ MaskDetectors::~MaskDetectors() {}
void MaskDetectors::init()
{
declareProperty(
new WorkspaceProperty<>("Workspace","", Direction::InOut),
new WorkspaceProperty<Workspace>("Workspace","", Direction::InOut),
"The name of the input and output workspace on which to perform the algorithm." );
declareProperty(new ArrayProperty<specid_t>("SpectraList"),
"An ArrayProperty containing a list of spectra to mask" );
......@@ -63,7 +64,14 @@ void MaskDetectors::init()
void MaskDetectors::exec()
{
// Get the input workspace
const MatrixWorkspace_sptr WS = getProperty("Workspace");
Workspace_sptr propWS = getProperty("Workspace");
MatrixWorkspace_sptr WS = boost::dynamic_pointer_cast<MatrixWorkspace>(propWS);
PeaksWorkspace_sptr peaksWS = boost::dynamic_pointer_cast<PeaksWorkspace>(propWS);
if (peaksWS)
{
execPeaks(peaksWS);
return;
}
// Is it an event workspace?
EventWorkspace_sptr eventWS = boost::dynamic_pointer_cast<EventWorkspace>(WS);
......@@ -189,7 +197,88 @@ void MaskDetectors::exec()
*/
WS->rebuildNearestNeighbours();
}
/*
* Peaks exec body
* @param WS :: The input peaks workspace to be masked
*/
void MaskDetectors::execPeaks(PeaksWorkspace_sptr WS)
{
std::vector<detid_t> detectorList = getProperty("DetectorList");
const MatrixWorkspace_sptr prevMasking = getProperty("MaskedWorkspace");
// each one of these values is optional but the user can't leave all four blank
if ( detectorList.empty() && !prevMasking )
{
g_log.information(name() + ": There is nothing to mask, "
"detector lists and masked workspace properties are all empty");
return;
}
// Need to get hold of the parameter map and instrument
Geometry::ParameterMap& pmap = WS->instrumentParameters();
Instrument_const_sptr instrument = WS->getInstrument();
// If we have a workspace that could contain masking,copy that in too
if( prevMasking )
{
DataObjects::MaskWorkspace_sptr maskWS = boost::dynamic_pointer_cast<DataObjects::MaskWorkspace>(prevMasking);
if (maskWS)
{
Geometry::ParameterMap& maskPmap = maskWS->instrumentParameters();
Instrument_const_sptr maskInstrument = maskWS->getInstrument();
if (maskInstrument->getDetectorIDs().size() != WS->getInstrument()->getDetectorIDs().size())
{
throw std::runtime_error("Size mismatch between input Workspace and MaskWorkspace");
}
g_log.debug() << "Extracting mask from MaskWorkspace (" << maskWS->name() << ")" << std::endl;
std::vector<detid_t> detectorIDs = maskInstrument->getDetectorIDs();
std::vector<detid_t>::const_iterator it;
for (it = detectorIDs.begin(); it != detectorIDs.end(); ++it)
{
try
{
if ( const Geometry::ComponentID det = maskInstrument->getDetector(*it)->getComponentID() )
{
Geometry::Parameter_sptr maskedParam = maskPmap.get(det, "masked");
int detID =static_cast<int>( maskInstrument->getDetector(*it)->getID());
if (maskedParam) detectorList.push_back(detID);
}
}
catch(Kernel::Exception::NotFoundError &e)
{
g_log.warning() << e.what() << " Found while running MaskDetectors" << std::endl;
}
}
}
}
// If explicitly given a list of detectors to mask, just mark those.
// Otherwise, mask all detectors pointing to the requested spectra in indexlist loop below
std::vector<detid_t>::const_iterator it;
if ( !detectorList.empty() )
{
for (it = detectorList.begin(); it != detectorList.end(); ++it)
{
try
{
if ( const Geometry::ComponentID det = instrument->getDetector(*it)->getComponentID() )
{
pmap.addBool(det,"masked",true);
}
}
catch(Kernel::Exception::NotFoundError &e)
{
g_log.warning() << e.what() << " Found while running MaskDetectors" << std::endl;
}
}
}
}
/**
* Convert a list of spectra numbers into the corresponding workspace indices
* @param indexList :: An output index list from the given spectra list
......
......@@ -130,7 +130,7 @@ public:
TS_ASSERT_EQUALS( props[0]->name(), "Workspace" );
TS_ASSERT( props[0]->isDefault() );
TS_ASSERT( dynamic_cast<WorkspaceProperty<>* >(props[0]) );
TS_ASSERT( dynamic_cast<WorkspaceProperty<Workspace>* >(props[0]) );
TS_ASSERT_EQUALS( props[1]->name(), "SpectraList" );
TS_ASSERT( props[1]->isDefault() );
......
......@@ -545,6 +545,23 @@ namespace DataObjects
detPos = det->getPos();
return true;
}
/*else //fix for gaps between tubes
{
beam = beam + V3D(0.00065,0.00065,0.00065);
tracker.traceFromSample(beam);
IDetector_const_sptr det1 = tracker.getDetectorResult();
beam = beam + V3D(-0.00065,-0.00065,-0.00065);
tracker.traceFromSample(beam);
IDetector_const_sptr det2 = tracker.getDetectorResult();
if (det1 && det2)
{
// Set the detector ID, the row, col, etc.
this->setDetectorID(static_cast<int>((det1->getID()+det1->getID())*0.5));;
// The old detector position is not more precise if it comes from FindPeaksMD
detPos = (det1->getPos() + det2->getPos())*0.5;
return true;
}
}*/
return false;
}
......
......@@ -133,20 +133,28 @@ namespace MDAlgorithms
V3D vecCentroid(centroid[0], centroid[1], centroid[2]);
// Save it back in the peak object, in the dimension specified.
if (CoordinatesToUse == 1) //"Q (lab frame)"
{
p.setQLabFrame( vecCentroid, detectorDistance);
p.findDetector();
}
else if (CoordinatesToUse == 2) //"Q (sample frame)"
{
p.setQSampleFrame( vecCentroid, detectorDistance);
p.findDetector();
}
else if (CoordinatesToUse == 3) //"HKL"
{
p.setHKL( vecCentroid );
}
try
{
if (CoordinatesToUse == 1) //"Q (lab frame)"
{
p.setQLabFrame( vecCentroid, detectorDistance);
p.findDetector();
}
else if (CoordinatesToUse == 2) //"Q (sample frame)"
{
p.setQSampleFrame( vecCentroid, detectorDistance);
p.findDetector();
}
else if (CoordinatesToUse == 3) //"HKL"
{
p.setHKL( vecCentroid );
}
}
catch (std::exception & e)
{
g_log.warning() << "Error setting Q or HKL" << std::endl;
g_log.warning() << e.what() << std::endl;
}
g_log.information() << "Peak " << i << " at " << pos << ": signal "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment