Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #6338 options for resolution shells and banks plus tests
- Loading branch information
1 parent
84fda71
commit 516d3e0
Showing
5 changed files
with
226 additions
and
7 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
119 changes: 119 additions & 0 deletions
119
Code/Mantid/Framework/Crystal/test/StatisticsOfPeaksWorkspaceTest.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,119 @@ | ||
#ifndef MANTID_CRYSTAL_STATISTICSOFPEAKSWORKSPACETEST_H_ | ||
#define MANTID_CRYSTAL_STATISTICSOFPEAKSWORKSPACETEST_H_ | ||
|
||
#include "MantidCrystal/StatisticsOfPeaksWorkspace.h" | ||
#include "MantidDataObjects/Peak.h" | ||
#include "MantidDataObjects/PeaksWorkspace.h" | ||
#include "MantidGeometry/IDTypes.h" | ||
#include "MantidKernel/System.h" | ||
#include "MantidKernel/Timer.h" | ||
#include "MantidTestHelpers/ComponentCreationHelper.h" | ||
#include "MantidGeometry/Crystal/OrientedLattice.h" | ||
#include <cxxtest/TestSuite.h> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <Poco/File.h> | ||
|
||
using namespace Mantid; | ||
using namespace Mantid::Crystal; | ||
using namespace Mantid::API; | ||
using namespace Mantid::Geometry; | ||
using namespace Mantid::Kernel; | ||
using namespace Mantid::DataObjects; | ||
using namespace Mantid::PhysicalConstants; | ||
|
||
class StatisticsOfPeaksWorkspaceTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
|
||
void test_Init() | ||
{ | ||
StatisticsOfPeaksWorkspace alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
} | ||
|
||
void do_test(int numRuns, size_t numBanks, size_t numPeaksPerBank) | ||
{ | ||
Instrument_sptr inst = ComponentCreationHelper::createTestInstrumentRectangular(4, 10, 1.0); | ||
PeaksWorkspace_sptr ws(new PeaksWorkspace()); | ||
ws->setInstrument(inst); | ||
|
||
auto lattice = new Mantid::Geometry::OrientedLattice; | ||
Mantid::Kernel::DblMatrix UB(3, 3, true); | ||
UB.identityMatrix(); | ||
lattice->setUB(UB); | ||
ws->mutableSample().setOrientedLattice(lattice); | ||
|
||
for (int run=1000; run<numRuns+1000; run++) | ||
for (size_t b=1; b<=numBanks; b++) | ||
for (size_t i=0; i<numPeaksPerBank; i++) | ||
{ | ||
V3D hkl(static_cast<double>(i), static_cast<double>(i), static_cast<double>(i)); | ||
DblMatrix gon(3,3, true); | ||
Peak p(inst, static_cast<detid_t>(b*100 + i+1+i*10), static_cast<double>(i)*1.0+0.5, hkl, gon); | ||
p.setRunNumber(run); | ||
p.setBankName("bank1"); | ||
p.setIntensity( static_cast<double>(i)+0.1); | ||
p.setSigmaIntensity( sqrt(static_cast<double>(i)+0.1)); | ||
p.setBinCount( static_cast<double>(i) ); | ||
ws->addPeak(p); | ||
} | ||
AnalysisDataService::Instance().addOrReplace("TOPAZ_peaks", ws); | ||
|
||
StatisticsOfPeaksWorkspace alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
TS_ASSERT_THROWS_NOTHING( alg.setProperty("InputWorkspace", "TOPAZ_peaks") ); | ||
TS_ASSERT_THROWS_NOTHING( alg.setProperty("SortBy", "Overall") ); | ||
TS_ASSERT_THROWS_NOTHING( alg.setProperty("StatisticsTable", "stat") ); | ||
TS_ASSERT_THROWS_NOTHING( alg.setProperty("OutputWorkspace", "TOPAZ_peaks") ); | ||
TS_ASSERT_THROWS_NOTHING( alg.execute(); ); | ||
TS_ASSERT( alg.isExecuted() ); | ||
|
||
ITableWorkspace_sptr tableOut; | ||
TS_ASSERT_THROWS_NOTHING( tableOut = boost::dynamic_pointer_cast<ITableWorkspace>( | ||
AnalysisDataService::Instance().retrieve("stat") ) ); | ||
TS_ASSERT(tableOut); | ||
if (!tableOut) return; | ||
TS_ASSERT_EQUALS( tableOut->rowCount(),1); | ||
TS_ASSERT_EQUALS( tableOut->String(0,0), "Overall"); | ||
TS_ASSERT_EQUALS( tableOut->Int(0,1), 3); | ||
TS_ASSERT_DELTA( tableOut->Double(0,2), 1.5,.1); | ||
TS_ASSERT_DELTA( tableOut->Double(0,3), 3.5,.1); | ||
TS_ASSERT_DELTA( tableOut->Double(0,4), 6.,.1); | ||
TS_ASSERT_DELTA( tableOut->Double(0,5), 1.4195,.1); | ||
TS_ASSERT_DELTA( tableOut->Double(0,6), 0.,.1); | ||
TS_ASSERT_DELTA( tableOut->Double(0,7), 0.,.1); | ||
|
||
PeaksWorkspace_sptr wsout; | ||
TS_ASSERT_THROWS_NOTHING( wsout = boost::dynamic_pointer_cast<PeaksWorkspace>( | ||
AnalysisDataService::Instance().retrieve("TOPAZ_peaks") ) ); | ||
TS_ASSERT(wsout); | ||
if (!wsout) return; | ||
TS_ASSERT_EQUALS( wsout->getNumberPeaks(), 24); | ||
|
||
Peak p = wsout->getPeaks()[0]; | ||
TS_ASSERT_EQUALS(p.getH(),1 ); | ||
TS_ASSERT_EQUALS(p.getK(),1 ); | ||
TS_ASSERT_EQUALS(p.getL(),1 ); | ||
TS_ASSERT_DELTA(p.getIntensity(),1.1, 1e-4); | ||
TS_ASSERT_DELTA(p.getSigmaIntensity(),1.0488, 1e-4); | ||
TS_ASSERT_DELTA(p.getWavelength(),1.5, 1e-4 ); | ||
TS_ASSERT_EQUALS(p.getRunNumber(),1000. ); | ||
TS_ASSERT_DELTA(p.getDSpacing(),3.5933, 1e-4 ); | ||
} | ||
|
||
/// Test with a few peaks | ||
void test_exec() | ||
{ | ||
do_test(2, 4,4); | ||
} | ||
|
||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_CRYSTAL_STATISTICSOFPEAKSWORKSPACETEST_H_ */ | ||
|
53 changes: 53 additions & 0 deletions
53
Code/Mantid/docs/source/algorithms/StatisticsOfPeaksWorkspace-v1.rst
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,53 @@ | ||
.. algorithm:: | ||
|
||
.. summary:: | ||
|
||
.. alias:: | ||
|
||
.. properties:: | ||
|
||
Description | ||
----------- | ||
|
||
Statistics of the Peaks Workspaces are calculated for all peaks and by | ||
default for resolution shell. There is a SortBy option to change this | ||
to by orientation (RunNumber) or by Anger camera (bank) or only do all peaks. | ||
|
||
Statistics include: | ||
No of Unique Reflections | ||
Resolution range | ||
Multiplicity | ||
Mean ((I)/sd(I)) | ||
Rmerge | ||
Rplm | ||
Data Completeness | ||
|
||
|
||
Usage | ||
----- | ||
|
||
**Example - an example of running StatisticsOfPeaksWorkspace with PointGroup option.** | ||
|
||
.. testcode:: ExStatisticsOfPeaksWorkspaceOption | ||
|
||
#load a peaks workspace from file | ||
peaks = LoadIsawPeaks(Filename=r'Peaks5637.integrate') | ||
LoadIsawUB(peaks,"ls5637.mat") | ||
peak = peaks.getPeak(0) | ||
print "HKL of first peak in table %d" % peak.getH(),peak.getK(),peak.getL() | ||
|
||
pw,stats = StatisticsOfPeaksWorkspace(InputWorkspace=peaks, PointGroup='-31m (Trigonal - Rhombohedral)', SortBy="Overall") | ||
peak = pw.getPeak(0) | ||
print "HKL of first peak in table %d" % peak.getH(),peak.getK(),peak.getL() | ||
print stats.row(0) | ||
|
||
Output: | ||
|
||
.. testoutput:: ExStatisticsOfPeaksWorkspaceOption | ||
|
||
HKL of first peak in table 1 4.0 -9.0 | ||
HKL of first peak in table -10 3.0 -40.0 | ||
{'Data Completeness': inf, 'Rmerge': 76.453114067956719, 'Multiplicity': 1.0074074074074073, 'Resolution Min': 0.29574100000000003, 'No. of Unique Reflections': 405, 'Mean ((I)/sd(I))': 27.50726166791943, 'Resolution Max': 3.1660760000000003, 'Resolution Shell': 'Overall', 'Rpim': 76.453114067956719} | ||
|
||
|
||
.. categories:: |