-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #9095. Started to implement algorith.
1. Add files; 2. Modify CMakeList; 3. Checkpointing work in progress
- Loading branch information
Showing
4 changed files
with
337 additions
and
0 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
88 changes: 88 additions & 0 deletions
88
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/EstimatePDDetectorResolution.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,88 @@ | ||
#ifndef MANTID_ALGORITHMS_ESTIMATEPDDETECTORRESOLUTION_H_ | ||
#define MANTID_ALGORITHMS_ESTIMATEPDDETECTORRESOLUTION_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
#include "MantidAPI/MatrixWorkspace.h" | ||
#include "MantidGeometry/Instrument.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
/** EstimatePDDetectorResolution : TODO: DESCRIPTION | ||
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 EstimatePDDetectorResolution : public API::Algorithm | ||
{ | ||
public: | ||
EstimatePDDetectorResolution(); | ||
virtual ~EstimatePDDetectorResolution(); | ||
|
||
/// Algorithm's name for identification overriding a virtual method | ||
virtual const std::string name() const { return "EstimatePDDetectorResolution";} | ||
/// Algorithm's version for identification overriding a virtual method | ||
virtual int version() const { return 1;} | ||
/// Algorithm's category for identification overriding a virtual method | ||
virtual const std::string category() const { return "Diffraction";} | ||
|
||
private: | ||
/// Sets documentation strings for this algorithm | ||
virtual void initDocs(); | ||
/// Implement abstract Algorithm methods | ||
void init(); | ||
/// Implement abstract Algorithm methods | ||
void exec(); | ||
|
||
/// | ||
void processAlgProperties(); | ||
|
||
/// | ||
void retrieveInstrumentParameters(); | ||
|
||
/// Create output workspace | ||
void createOutputWorkspace(); | ||
|
||
/// Calculate detector resolution | ||
void estimateDetectorResolution(); | ||
|
||
|
||
//------------------------------------------------------ | ||
|
||
/// Input workspace | ||
API::MatrixWorkspace_sptr m_inputWS; | ||
|
||
/// Output workspace | ||
API::MatrixWorkspace_sptr m_outputWS; | ||
|
||
API::MatrixWorkspace_sptr m_solidangleWS; | ||
|
||
/// Centre neutron velocity | ||
double m_centreVelocity; | ||
|
||
}; | ||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_ALGORITHMS_ESTIMATEPDDETECTORRESOLUTION_H_ */ |
182 changes: 182 additions & 0 deletions
182
Code/Mantid/Framework/Algorithms/src/EstimatePDDetectorResolution.cpp
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,182 @@ | ||
/*WIKI* | ||
*WIKI*/ | ||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAlgorithms/EstimatePDDetectorResolution.h" | ||
#include "MantidAPI/WorkspaceProperty.h" | ||
#include "MantidKernel/PhysicalConstants.h" | ||
#include "MantidKernel/TimeSeriesProperty.h" | ||
#include "MantidKernel/V3D.h" | ||
|
||
using namespace Mantid; | ||
using namespace Mantid::API; | ||
using namespace Mantid::Geometry; | ||
using namespace Mantid::Kernel; | ||
|
||
using namespace std; | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
DECLARE_ALGORITHM(EstimatePDDetectorResolution) | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
EstimatePDDetectorResolution::EstimatePDDetectorResolution() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
EstimatePDDetectorResolution::~EstimatePDDetectorResolution() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** | ||
*/ | ||
void EstimatePDDetectorResolution::initDocs() | ||
{ | ||
setWikiSummary("Estimate the resolution of each detector for a powder diffractometer. "); | ||
setOptionalMessage("Estimate the resolution of each detector for a powder diffractometer. "); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
void EstimatePDDetectorResolution::init() | ||
{ | ||
declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "", Direction::Input), | ||
"Name of the workspace to have detector resolution calculated. "); | ||
|
||
declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace", "", Direction::Output), | ||
"Name of the output workspace containing delta(d)/d of each detector/spectrum. "); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** | ||
*/ | ||
void EstimatePDDetectorResolution::exec() | ||
{ | ||
processAlgProperties(); | ||
|
||
retrieveInstrumentParameters(); | ||
|
||
createOutputWorkspace(); | ||
|
||
estimateDetectorResolution(); | ||
|
||
setProperty("OutputWorkspace", m_outputWS); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** | ||
*/ | ||
void EstimatePDDetectorResolution::processAlgProperties() | ||
{ | ||
m_inputWS = getProperty("InputWorkspace"); | ||
|
||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** | ||
*/ | ||
void EstimatePDDetectorResolution::retrieveInstrumentParameters() | ||
{ | ||
// Call SolidAngle to get solid angles for all detectors | ||
Algorithm_sptr calsolidangle = createChildAlgorithm("SolidAngle", -1, -1, true); | ||
calsolidangle->initialize(); | ||
|
||
calsolidangle->setProperty("InputWorkspace", m_inputWS); | ||
|
||
calsolidangle->execute(); | ||
if (!calsolidangle->isExecuted()) | ||
throw runtime_error("Unable to run solid angle. "); | ||
|
||
m_solidangleWS = calsolidangle->getProperty("OutputWorkspace"); | ||
if (!m_solidangleWS) | ||
throw runtime_error("Unable to get solid angle workspace from SolidAngle(). "); | ||
|
||
|
||
size_t numspec = m_solidangleWS->getNumberHistograms(); | ||
for (size_t i = 0; i < numspec; ++i) | ||
g_log.debug() << "[DB]: " << m_solidangleWS->readY(i)[0] << "\n"; | ||
|
||
// Calculate centre neutron velocity | ||
Property* cwlproperty = m_inputWS->run().getProperty("LambdaRequest"); | ||
if (!cwlproperty) | ||
throw runtime_error("Unable to locate property LambdaRequest as central wavelength. "); | ||
TimeSeriesProperty<double>* cwltimeseries = dynamic_cast<TimeSeriesProperty<double>* >(cwlproperty); | ||
if (!cwltimeseries) | ||
throw runtime_error("LambdaReqeust is not a TimeSeriesProperty in double. "); | ||
if (cwltimeseries->size() != 1) | ||
throw runtime_error("LambdaRequest should contain 1 and only 1 entry. "); | ||
|
||
double centrewavelength = cwltimeseries->nthValue(0); | ||
string unit = cwltimeseries->units(); | ||
if (unit.compare("Angstrom") == 0) | ||
centrewavelength *= 1.0E-10; | ||
else | ||
throw runtime_error("Unit is not recognized"); | ||
|
||
m_centreVelocity = PhysicalConstants::h/PhysicalConstants::NeutronMass/centrewavelength; | ||
g_log.notice() << "Centre wavelength = " << centrewavelength << ", Centre neutron velocity = " << m_centreVelocity << "\n"; | ||
|
||
// Calcualte L1 sample to source | ||
Instrument_const_sptr instrument = m_inputWS->getInstrument(); | ||
V3D samplepos = instrument->getSample()->getPos(); | ||
V3D sourcepos = instrument->getSource()->getPos(); | ||
double m_L1 = samplepos.distance(sourcepos); | ||
g_log.notice() << "L1 = " << m_L1 << "\n"; | ||
|
||
return; | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** | ||
*/ | ||
void EstimatePDDetectorResolution::createOutputWorkspace() | ||
{ | ||
size_t numspec = m_inputWS->getNumberHistograms(); | ||
|
||
m_outputWS = boost::dynamic_pointer_cast<MatrixWorkspace>( | ||
WorkspaceFactory::Instance().create("Workspace2D", numspec, 1, 1)); | ||
|
||
return; | ||
} | ||
//---------------------------------------------------------------------------------------------- | ||
/** | ||
*/ | ||
void EstimatePDDetectorResolution::estimateDetectorResolution() | ||
{ | ||
size_t numspec = m_inputWS->getNumberHistograms(); | ||
for (size_t i = 0; i < numspec; ++i) | ||
{ | ||
// Get the distance from | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
return; | ||
} | ||
|
||
} // namespace Algorithms | ||
} // namespace Mantid |
64 changes: 64 additions & 0 deletions
64
Code/Mantid/Framework/Algorithms/test/EstimatePDDetectorResolutionTest.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,64 @@ | ||
#ifndef MANTID_ALGORITHMS_ESTIMATEPDDETECTORRESOLUTIONTEST_H_ | ||
#define MANTID_ALGORITHMS_ESTIMATEPDDETECTORRESOLUTIONTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidAlgorithms/EstimatePDDetectorResolution.h" | ||
#include "MantidDataHandling/LoadNexusProcessed.h" | ||
|
||
using Mantid::Algorithms::EstimatePDDetectorResolution; | ||
|
||
using namespace Mantid::API; | ||
using namespace Mantid::Kernel; | ||
|
||
class EstimatePDDetectorResolutionTest : 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 EstimatePDDetectorResolutionTest *createSuite() { return new EstimatePDDetectorResolutionTest(); } | ||
static void destroySuite( EstimatePDDetectorResolutionTest *suite ) { delete suite; } | ||
|
||
|
||
/** Test init | ||
*/ | ||
void test_Init() | ||
{ | ||
EstimatePDDetectorResolution alg; | ||
TS_ASSERT_THROWS_NOTHING(alg.initialize()); | ||
TS_ASSERT(alg.isInitialized()); | ||
} | ||
|
||
/** Test POWGEN | ||
*/ | ||
void test_PG3() | ||
{ | ||
// Load data file | ||
Mantid::DataHandling::LoadNexusProcessed loader; | ||
loader.initialize(); | ||
loader.setProperty("Filename","PG3_2538_meta.nxs"); | ||
loader.setProperty("OutputWorkspace", "PG3_2538"); | ||
loader.execute(); | ||
|
||
// Set up and run | ||
EstimatePDDetectorResolution alg; | ||
alg.initialize(); | ||
|
||
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("InputWorkspace", "PG3_2538")); | ||
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "PG3_Resolution")); | ||
|
||
alg.execute(); | ||
TS_ASSERT(alg.isExecuted()); | ||
|
||
|
||
|
||
AnalysisDataService::Instance().remove("PG3_2538"); | ||
|
||
TS_ASSERT_EQUALS(1, 3); | ||
} | ||
|
||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_ALGORITHMS_ESTIMATEPDDETECTORRESOLUTIONTEST_H_ */ |