Skip to content

Commit

Permalink
RE 7248_MantidEV_show_distance_between_last_points_picked
Browse files Browse the repository at this point in the history
Initial version, works if Q is in sample coordinates for
both Q and HKL.  In order for this to work for HKL when
Q is in lab coordinates we will need to get and apply
the goniometer rotation.

refs #7248
  • Loading branch information
DennisMikkelson committed Jun 10, 2013
1 parent aca9596 commit 1f21e02
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ private slots:
std::string last_ini_file; /// filename of last settings file that was
/// loaded or saved, if any.

Mantid::Kernel::V3D last_Q; /// the last_Q vector that was received from
/// the SelectionNotificationService

QThreadPool *m_thread_pool; /// local thread pool with only one thread to
/// allow running precisely one operation
/// at a time in a separate thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class DLLExport MantidEVWorker
/// Display UB and lattice parameters in MantidPlot
bool showUB( const std::string & peaks_ws_name );

/// Get the current UB matrix from the peaks workspace
bool getUB( const std::string & peaks_ws_name,
Mantid::Kernel::Matrix<double> & UB );

/// Get Info about a Q-Vector from a PeaksWorkspace
std::vector< std::pair< std::string, std::string > >
PointInfo( const std::string & peaks_ws_name,
Expand Down
23 changes: 22 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/MantidEV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ void RunEllipsoidIntegrate::run()
*/
MantidEV::MantidEV(QWidget *parent) : UserSubWindow(parent)
{
last_Q = V3D(0,0,0);
worker = new MantidEVWorker();
m_thread_pool = new QThreadPool( this );
m_thread_pool->setMaxThreadCount(1);
Expand Down Expand Up @@ -1121,7 +1122,7 @@ void MantidEV::QPointSelection_slot( bool lab_coords, double qx, double qy, doub
*
* @param lab_coords Will be true if the Q-components are in lab coordinates
* and false if they are in sample coordinates.
* @param q_point Vector containing the Q-coordinates.
* @param q_point Vector containing the Q-coordinates.
*/
void MantidEV::showInfo( bool lab_coords, Mantid::Kernel::V3D q_point )
{
Expand All @@ -1148,6 +1149,26 @@ void MantidEV::showInfo( bool lab_coords, Mantid::Kernel::V3D q_point )
info = worker->PointInfo( peaks_ws_name, lab_coords, q_point );
}

double q_dist = ( q_point - last_Q ).norm();
std::pair<std::string, std::string> Q_dist_str("|Q2-Q1|", boost::lexical_cast<std::string>(q_dist));
info.push_back( Q_dist_str );

Mantid::Kernel::Matrix<double> UB(3,3,false);
if ( worker->getUB( peaks_ws_name, UB ) ) // if the peaks workspace has a UB, also find the
{ // distance between points in HKL.
Mantid::Kernel::Matrix<double> UBinv( UB );
UBinv.Invert();
Mantid::Kernel::V3D hkl_1 = UBinv * last_Q;
Mantid::Kernel::V3D hkl_2 = UBinv * q_point;
hkl_1 = hkl_1 / (2 * M_PI);
hkl_2 = hkl_2 / (2 * M_PI);
double hkl_dist = (hkl_2 - hkl_1).norm();
std::pair<std::string, std::string> hkl_dist_str("|hkl2-hkl1|", boost::lexical_cast<std::string>(hkl_dist));
info.push_back( hkl_dist_str );
}

last_Q = q_point;

m_uiForm.SelectedPoint_tbl->setRowCount((int)info.size());
m_uiForm.SelectedPoint_tbl->setColumnCount(2);
m_uiForm.SelectedPoint_tbl->verticalHeader()->hide();
Expand Down
36 changes: 36 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MantidEVWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,42 @@ bool MantidEVWorker::showUB( const std::string & peaks_ws_name )
}


/**
* Get the current UB matrix from the specified peaks workspace.
*
* @param peaks_ws_name The name of the peaks workspace with the UB
* matrix.
* @param UB 3x3 matrix of doubles to be filled out with
* the UB matrix if one exists in the specified
* peaks workspace.
* @return true if the UB matrix was found and returned in the UB
* parameter.
*/
bool MantidEVWorker::getUB( const std::string & peaks_ws_name,
Mantid::Kernel::Matrix<double> & UB )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
{
return false;
}

const auto& ADS = AnalysisDataService::Instance();
IPeaksWorkspace_sptr peaks_ws = ADS.retrieveWS<IPeaksWorkspace>(peaks_ws_name);

try
{
Mantid::Geometry::OrientedLattice o_lattice = peaks_ws->mutableSample().getOrientedLattice();
UB = o_lattice.getUB();
}
catch(...)
{
return false;
}

return true;
}


/**
* Get information about a specified Q-position from the specified peaks
* workspace.
Expand Down

0 comments on commit 1f21e02

Please sign in to comment.