Skip to content

Commit

Permalink
Refs #6550 Reverted this commit elsewhere.
Browse files Browse the repository at this point in the history
Revert "Refs #6550  Added Tilt parameter and 3 output values per peak"

This reverts commit 9e1bb61.
  • Loading branch information
RuthFromDuluth committed Mar 23, 2013
1 parent 1a6738c commit aac3eea
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 724 deletions.

This file was deleted.

27 changes: 0 additions & 27 deletions Code/Mantid/Framework/API/src/SelectionNotificationService.cpp

This file was deleted.

25 changes: 1 addition & 24 deletions Code/Mantid/Framework/Crystal/inc/MantidCrystal/PeakHKLErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidAPI/IFunction.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidKernel/Matrix.h"
using Mantid::API::IFunction;
using Mantid::Geometry::Instrument;
using Mantid::DataObjects::PeaksWorkspace_sptr;
Expand All @@ -29,28 +28,10 @@ namespace Mantid
/** IndexOptimizePeaks
Description:
This algorithm basically indexes peaks with the sample orientation matrix stored in the peaks workspace.
This algorithm basically indexes peaks with the crystal orientation matrix stored in the peaks workspace.
The optimization is on the goniometer settings for the runs in the peaks workspace and also the sample
orientation is optimized.
Attributes:
OptRuns : a list of run numbers whose sample orientations are to be optimized. The list is separated by /.
PeakWorkspaceName : The name of the PeaksWorkspace in the AnalysisDataService
Parameters:
SampleXOffset
SampleYOffset
SampleZOffset
chixxx - xxx is a run number from OptRuns. This is the chi angle in degrees
phixxx - xxx is a run number from OptRuns. This is the phi angle in degrees
omegaxxx - xxx is a run number from OptRuns. This is the omega angle in degrees
Workspace:
For each peak used, there are 3 pieces of Data, one for the h int offset, one for the k int offset and one for
the l int offset. The x Values represent the peak number in the peaks workspace.
Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Expand Down Expand Up @@ -112,10 +93,6 @@ namespace Mantid
return (size_t) 2;
}

static Kernel::Matrix<double> DerivRotationMatrixAboutRegAxis( double theta, char axis);

static Kernel::Matrix<double> RotationMatrixAboutRegAxis( double theta, char axis);

boost::shared_ptr<Geometry::Instrument>
getNewInstrument(DataObjects::PeaksWorkspace_sptr Peaks) const;

Expand Down
116 changes: 20 additions & 96 deletions Code/Mantid/Framework/Crystal/src/OptimizeCrystalPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,18 @@ namespace Mantid
"Workspace of Results");


declareProperty("AdjustSampleOffsets", true,
declareProperty("IncludeVaryingSampleOffsets", true,
"If true sample offsets will be adjusted to give better fits, otherwise they will be fixed as zero(def=true)");

declareProperty("OptimizeGoniometerTilt", false, "Set true if main error is due to a tilted Goniometer(def=false)");

declareProperty("Chi2overDoF", -1.0, "chi squared over dof", Direction::Output);
declareProperty("nPeaks", -1, "Number of Peaks Used", Direction::Output);
declareProperty("nParams", -1, "Number of Parameters fit", Direction::Output);


declareProperty("MaxAngularChange", 5.0, "Max offset in degrees from current settings(def=5)");
declareProperty("ToleranceChiPhiOmega", 5.0, "Max offset in degrees from current settings(def=5)");

declareProperty("MaxIndexingError", .25,
"Use only peaks whose fractional hkl values are below this tolerance(def=.25)");
declareProperty("MaxIntHKLOffsetPeaks2Use", .25,
"Use only peaks whose h,k,and l offsets from and integer are below this level(def=.25)");

declareProperty(
"MaxHKLPeaks2Use", -1.0,
Expand All @@ -107,20 +105,15 @@ namespace Mantid
"Maximum Change in Sample position in meters(def=.005)");


setPropertyGroup("MaxAngularChange", "Tolerance settings");
setPropertyGroup("ToleranceChiPhiOmega", "Tolerance settings");

setPropertyGroup("MaxSamplePositionChange_meters", "Tolerance settings");
setPropertyGroup("MaxHKLPeaks2Use", "Tolerance settings");
setPropertyGroup("MaxIndexingError", "Tolerance settings");
setPropertyGroup("MaxIntHKLOffsetPeaks2Use", "Tolerance settings");

setPropertySettings("MaxSamplePositionChange_meters",new EnabledWhenProperty("AdjustSampleOffsets",
setPropertySettings("MaxSamplePositionChange_meters",new EnabledWhenProperty("IncludeVaryingSampleOffsets",
Kernel::IS_EQUAL_TO, "1" ));

//-------- Output values----------------------------------
//Sample offset and goniometer tilt. Can be retrieved from tables, but....



}

void OptimizeCrystalPlacement::exec()
Expand Down Expand Up @@ -149,7 +142,7 @@ namespace Mantid
Mantid::MantidVec &errB = errs.access();

int nPeaksUsed =0;
double HKLintOffsetMax= getProperty("MaxIndexingError");
double HKLintOffsetMax= getProperty("MaxIntHKLOffsetPeaks2Use");
double HKLMax=getProperty("MaxHKLPeaks2Use");
for ( int i = 0; i < Peaks->getNumberPeaks(); i++ )
{
Expand Down Expand Up @@ -190,17 +183,11 @@ namespace Mantid
xRef.push_back( ( double ) i );
yvalB.push_back( 0.0 );
errB.push_back( 1.0 );
xRef.push_back( ( double ) i );
yvalB.push_back( 0.0 );
errB.push_back( 1.0 );
xRef.push_back( ( double ) i );
yvalB.push_back( 0.0 );
errB.push_back( 1.0 );

}

MatrixWorkspace_sptr mwkspc;
int N = 3*nPeaksUsed;//Peaks->getNumberPeaks();
int N = Peaks->getNumberPeaks();
mwkspc = WorkspaceFactory::Instance().create( "Workspace2D" , (size_t) 1 , N , N );
mwkspc->setX( 0 , pX );
mwkspc->setData( 0 , yvals , errs );
Expand Down Expand Up @@ -243,7 +230,7 @@ namespace Mantid


int nParams=3;
double DegreeTol=getProperty("MaxAngularChange");
double DegreeTol=getProperty("ToleranceChiPhiOmega");
std::string startConstraint ="";
for ( size_t i = 0; i < RunNumList.size(); i++ )
{
Expand Down Expand Up @@ -276,11 +263,11 @@ namespace Mantid
V3D sampPos = instr->getSample()->getPos();

oss<< ",SampleXOffset="<<sampPos.X()<<",SampleYOffset="<<sampPos.Y()<<",SampleZOffset="<<sampPos.Z();
oss<<",GonRotx=0.0,GonRoty=0.0,GonRotz=0.0";

double maxSampshift = getProperty("MaxSamplePositionChange_meters");
oss1 << startConstraint << sampPos.X()-maxSampshift<<"<SampleXOffset<"<<sampPos.X()+maxSampshift<<","<<sampPos.Y()-maxSampshift<<
"<SampleYOffset<"<<sampPos.Y()+maxSampshift <<","<<sampPos.Z()-maxSampshift<<"<SampleZOffset<" <<sampPos.Z()+maxSampshift;
oss1<<","<<-DegreeTol<<"<GonRotx<"<<DegreeTol<<","<<-DegreeTol<<"<GonRoty<"<<DegreeTol<<","<<-DegreeTol<<"<GonRotz<"<<DegreeTol;

FuncArg += oss.str();
std::string Constr = oss1.str();

Expand All @@ -301,28 +288,15 @@ namespace Mantid

fit_alg->setProperty( "CreateOutput" , true );

std::string Ties ="";
if( !(bool)getProperty("AdjustSampleOffsets"))
if( !(bool)getProperty("IncludeVaryingSampleOffsets"))
{
std::ostringstream oss3( std::ostringstream::out );
oss3.precision( 3 );
std::ostringstream oss( std::ostringstream::out );
oss.precision( 3 );
oss<<"SampleXOffset="<<sampPos.X()<<",SampleYOffset="<<sampPos.Y()<<",SampleZOffset="<<sampPos.Z();

oss3<<"SampleXOffset="<<sampPos.X()<<",SampleYOffset="<<sampPos.Y()<<",SampleZOffset="<<sampPos.Z();
Ties =oss3.str();
fit_alg->setProperty("Ties",oss.str());
}

if( !(bool)getProperty("OptimizeGoniometerTilt"))
{
if( !Ties.empty())
Ties +=",";

Ties +="GonRotx=0.0,GonRoty=0.0,GonRotz=0.0";

}

if( !Ties.empty())
fit_alg->setProperty("Ties",Ties);

fit_alg->setProperty( "Output" , "out" );

fit_alg->executeAsChildAlg();
Expand All @@ -337,10 +311,8 @@ namespace Mantid

setProperty( "nPeaks", nPeaksUsed) ;
setProperty("nParams", nParams );

g_log.debug() << "Chi2overDof=" << chisq <<" # Peaks used="<< nPeaksUsed
<< "# fitting parameters ="<< nParams << " dof=" << (nPeaksUsed - nParams) <<std::endl;

ITableWorkspace_sptr RRes = fit_alg->getProperty( "OutputParameters" );

double sigma = sqrt( chisq );
Expand Down Expand Up @@ -369,7 +341,7 @@ namespace Mantid
std::string namee = RRes->getRef<std::string> ( "Name" , prm );

std::string start= namee.substr(0,3);
if( start !="chi" && start !="phi" && start !="ome" && start !="Sam" && start!="Gon")
if( start !="chi" && start !="phi" && start !="ome" && start !="Sam")
continue;

double value = RRes->getRef<double>("Value",prm);
Expand All @@ -383,14 +355,11 @@ namespace Mantid
}

//-----------Fix up Resultant workspace return info -------------------

std::string ResultWorkspaceName = getPropertyValue( "FitInfoTable" );
AnalysisDataService::Instance().addOrReplace( ResultWorkspaceName , RRes );

setPropertyValue( "FitInfoTable" , ResultWorkspaceName );

//----------- update instrument -------------------------

IPeak& peak =Peaks->getPeak(0);
boost::shared_ptr<const Instrument>OldInstrument = peak.getInstrument();
boost::shared_ptr<const ParameterMap>pmap_old = OldInstrument->getParameterMap();
Expand Down Expand Up @@ -419,10 +388,6 @@ namespace Mantid
OutPeaks->setInstrument( NewInstrument );


Matrix<double> GonTilt = PeakHKLErrors::RotationMatrixAboutRegAxis( Results["GonRotx"] ,'x')*
PeakHKLErrors::RotationMatrixAboutRegAxis( Results["GonRoty"] ,'y')*
PeakHKLErrors::RotationMatrixAboutRegAxis( Results["GonRotz"] ,'z');
/* std::set<int> RunNums;
for( std::vector<std::string>::iterator it =ChRunNumList.begin(); it !=ChRunNumList.end(); ++it)
{
std::string runNumStr = *it;
Expand All @@ -437,56 +402,15 @@ namespace Mantid
uniGonio.setRotationAngle( "chi", chi );
uniGonio.setRotationAngle( "omega", omega) ;

Matrix<double> GonMatrix = GonTilt*uniGonio.getR();
Matrix<double> GonMatrix = uniGonio.getR();

for( int i = 0 ; i < OutPeaks->getNumberPeaks() ; ++i)
if( OutPeaks->getPeak(i).getRunNumber()== boost::lexical_cast<int>(runNumStr))
{
OutPeaks->getPeak( i ).setGoniometerMatrix( GonMatrix );

}
else
RunNums.insert( OutPeaks->getPeak(i).getRunNumber());
}
*/
int prevRunNum = -1;
std::map<int, Matrix<double> > MapRunNum2GonMat;
std::string OptRun2 ="/"+OptRunNums+"/";
for (int i = 0; i < OutPeaks->getNumberPeaks(); ++i)
{

int RunNum = OutPeaks->getPeak(i).getRunNumber();
std::string RunNumStr = boost::lexical_cast<std::string>(RunNum);
Matrix<double> GonMatrix;
if (RunNum == prevRunNum || MapRunNum2GonMat.find(RunNum) != MapRunNum2GonMat.end())
GonMatrix = MapRunNum2GonMat[RunNum];
else if (OptRun2.find("/" + RunNumStr + "/") < OptRun2.size() - 2)
{

double chi = Results["chi" + RunNumStr];
double phi = Results["phi" + RunNumStr];
double omega = Results["omega" + RunNumStr];

Mantid::Geometry::Goniometer uniGonio;
uniGonio.makeUniversalGoniometer();

uniGonio.setRotationAngle("phi", phi);
uniGonio.setRotationAngle("chi", chi);
uniGonio.setRotationAngle("omega", omega);

GonMatrix = GonTilt * uniGonio.getR();
MapRunNum2GonMat[RunNum] = GonMatrix;
}
else
{
GonMatrix = GonTilt * OutPeaks->getPeak(i).getGoniometerMatrix();
MapRunNum2GonMat[RunNum] = GonMatrix;
}

OutPeaks->getPeak(i).setGoniometerMatrix( GonMatrix );
prevRunNum= RunNum;
}
}


std::string OutputPeaksName= getPropertyValue("ModifiedPeaksWorkspace");
Expand Down

0 comments on commit aac3eea

Please sign in to comment.