Skip to content

Commit

Permalink
Refs #9325 works without scaling or corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Apr 15, 2014
1 parent 2f9b3c5 commit 589fa3f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
42 changes: 30 additions & 12 deletions Code/Mantid/Framework/Crystal/src/SaveHKL.cpp
Expand Up @@ -47,6 +47,7 @@ Last line must have all 0's
#include "MantidKernel/ListValidator.h"
#include <boost/math/special_functions/fpclassify.hpp>
#include <fstream>
#include "Poco/File.h"

using namespace Mantid::Geometry;
using namespace Mantid::DataObjects;
Expand Down Expand Up @@ -128,8 +129,10 @@ namespace Crystal
declareProperty("SortBy", histoTypes[2],boost::make_shared<StringListValidator>(histoTypes),
"Sort the histograms by bank, run number or both (default).");
declareProperty("MinIsigI", EMPTY_DBL(), mustBePositive,
"The minimum I/sig(I) ratio");
"The minimum I/sig(I) ratio");
declareProperty("WidthBorder", EMPTY_INT(), "Width of border of detectors");
declareProperty("MinIntensity", EMPTY_DBL(), mustBePositive,
"The minimum Intensity");
}

//----------------------------------------------------------------------------------------------
Expand All @@ -146,6 +149,7 @@ namespace Crystal
double wlMax = getProperty("MaxWavelength");
std::string type = getProperty("SortBy");
double minIsigI = getProperty("MinIsigI");
double minIntensity = getProperty("MinIntensity");
int widthBorder = getProperty("WidthBorder");

// Sequence and run number
Expand Down Expand Up @@ -175,27 +179,37 @@ namespace Crystal

std::fstream out;
bool append = getProperty("AppendFile");
if (append)
if (append && Poco::File(filename.c_str()).exists())
{
out.open( filename.c_str(), std::ios::in|std::ios::out|std::ios::ate);
std::streamoff pos = out.tellp();
out.seekp (28);
out >> runSequence;
out.seekp (pos - 110);
out >> seqNum;
out.seekp (pos - 73);
seqNum ++;
IAlgorithm_sptr load_alg = createChildAlgorithm("LoadHKL");
load_alg->setPropertyValue("Filename", filename.c_str());
load_alg->setProperty("OutputWorkspace", "peaks");
load_alg->executeAsChildAlg();
// Get back the result
DataObjects::PeaksWorkspace_sptr ws2 = load_alg->getProperty("OutputWorkspace");
ws2->setInstrument(ws->getInstrument());

IAlgorithm_sptr plus_alg = createChildAlgorithm("CombinePeaksWorkspaces");
plus_alg->setProperty("LHSWorkspace", ws);
plus_alg->setProperty("RHSWorkspace", ws2);
plus_alg->executeAsChildAlg();
// Get back the result
ws = plus_alg->getProperty("OutputWorkspace");
out.open( filename.c_str(), std::ios::out);
}
else
{
out.open( filename.c_str(), std::ios::out);
out.open( filename.c_str(), std::ios::out);
}

// We must sort the peaks by bank #
std::vector< std::pair<std::string, bool> > criteria;
if(type.compare(0,2,"Ba")==0) criteria.push_back( std::pair<std::string, bool>("BankName", true) );
else if(type.compare(0,2,"Ru")==0) criteria.push_back( std::pair<std::string, bool>("RunNumber", true) );
else criteria.push_back( std::pair<std::string, bool>("BankName", true) );
criteria.push_back( std::pair<std::string, bool>("h", true) );
criteria.push_back( std::pair<std::string, bool>("k", true) );
criteria.push_back( std::pair<std::string, bool>("l", true) );
ws->sort(criteria);

bool correctPeaks = getProperty("ApplyAnvredCorrections");
Expand Down Expand Up @@ -299,6 +313,7 @@ namespace Crystal
if (p.getIntensity() == 0.0 || boost::math::isnan(p.getIntensity()) ||
boost::math::isnan(p.getSigmaIntensity())) continue;
if (minIsigI != EMPTY_DBL() && p.getIntensity() < std::abs(minIsigI * p.getSigmaIntensity())) continue;
if (minIntensity != EMPTY_DBL() && p.getIntensity() < minIntensity) continue;
int run = p.getRunNumber();
int bank = 0;
std::string bankName = p.getBankName();
Expand Down Expand Up @@ -377,7 +392,9 @@ namespace Crystal
}

// SHELX can read data without the space between the l and intensity
out << std::setw( 8 ) << std::fixed << std::setprecision( 2 ) << correc*p.getIntensity();
double ckIntensity = correc*p.getIntensity();
if (ckIntensity > 99999.985) g_log.warning() << "Scaled intensity, " << ckIntensity << " is too large for format. Decrease ScalePeaks.\n";
out << std::setw( 8 ) << std::fixed << std::setprecision( 2 ) << ckIntensity;

out << std::setw( 8 ) << std::fixed << std::setprecision( 2 ) <<
std::sqrt(std::pow(correc*p.getSigmaIntensity(),2)+std::pow(relSigSpect*correc*p.getIntensity(),2));
Expand Down Expand Up @@ -528,6 +545,7 @@ namespace Crystal
{
if (bankName.compare("None") == 0) return;
boost::shared_ptr<const IComponent> parent = ws->getInstrument()->getComponentByName(bankName);
if(!parent) return;
if (parent->type().compare("RectangularDetector") == 0)
{
boost::shared_ptr<const RectangularDetector> RDet = boost::dynamic_pointer_cast<
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Crystal/test/SaveHKLTest.h
Expand Up @@ -92,7 +92,7 @@ class SaveHKLTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(d7,1.5 );
TS_ASSERT_EQUALS(d8,0.1591 );
TS_ASSERT_EQUALS(d9,1000. );
TS_ASSERT_EQUALS(d10,2 );
TS_ASSERT_EQUALS(d10,9 );
TS_ASSERT_EQUALS(d11,0.9434 );
TS_ASSERT_EQUALS(d12,1 );
TS_ASSERT_DELTA(d13,0.4205 , 1e-4);
Expand Down

0 comments on commit 589fa3f

Please sign in to comment.