Skip to content

Commit

Permalink
Merge pull request #14942 from mantidproject/14932_allow_user_to_rota…
Browse files Browse the repository at this point in the history
…te_source_after_reflReductionOne_has_run

Allow user to rotate source to a different position after ReflectometryReduction has run
  • Loading branch information
raquelalvarezbanos committed Jan 14, 2016
2 parents ff84eb5 + bfca395 commit 34a24f9
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class DLLExport ReflectometryReductionOne : public ReflectometryWorkflowBase {
void verifySpectrumMaps(API::MatrixWorkspace_const_sptr ws1,
API::MatrixWorkspace_const_sptr ws2,
const bool severe = false);
/// returns angle for source rotation
double getAngleForSourceRotation(API::MatrixWorkspace_sptr toConvert,
double thetaOut);
};

} // namespace Algorithms
Expand Down
38 changes: 27 additions & 11 deletions Framework/Algorithms/src/ReflectometryReductionOne.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,29 @@ ReflectometryReductionOne::correctPosition(API::MatrixWorkspace_sptr &toCorrect,

return corrected;
}
/**
* @param toConvert : workspace used to get instrument components
* @param thetaOut : angle between sample and detectors (in Degrees)
* @return Theta : the value by which we rotate the source (in Degrees)
*/
double ReflectometryReductionOne::getAngleForSourceRotation(
MatrixWorkspace_sptr toConvert, double thetaOut) {
auto instrument = toConvert->getInstrument();
auto instrumentUpVector = instrument->getReferenceFrame()->vecPointingUp();
// check to see if calculated theta is the same as theta from instrument setup
auto instrumentBeamDirection = instrument->getBeamDirection();
double currentThetaInFromInstrument =
instrumentUpVector.angle(instrumentBeamDirection) * (180 / M_PI) - 90;
bool isInThetaEqualToOutTheta =
std::abs(currentThetaInFromInstrument - thetaOut) <
Mantid::Kernel::Tolerance;
// the angle by which we rotate the source
double rotationTheta = 0.0;
if (!isInThetaEqualToOutTheta /*source needs rotation*/) {
rotationTheta = thetaOut - currentThetaInFromInstrument;
}
return rotationTheta;
}

/**
* Convert an input workspace into an IvsQ workspace.
Expand Down Expand Up @@ -349,23 +372,16 @@ Mantid::API::MatrixWorkspace_sptr ReflectometryReductionOne::toIvsQ(
} else if (bCorrectPosition) {
toConvert = correctPosition(toConvert, thetaInDeg.get(), isPointDetector);
}

auto instrument = toConvert->getInstrument();
auto instrumentSourcePosition =
toConvert->getInstrument()->getSource()->getPos();
auto instrumentUpVector =
toConvert->getInstrument()->getReferenceFrame()->vecPointingUp();
bool isSourcePerpendicularToUpVec =
instrumentSourcePosition.scalar_prod(instrumentUpVector) == 0;

if (isSourcePerpendicularToUpVec /*source hasn't rotated*/) {
double rotationTheta = getAngleForSourceRotation(toConvert, thetaInDeg.get());
if (rotationTheta != 0.0) {
auto rotateSource = this->createChildAlgorithm("RotateSource");
rotateSource->setChild(true);
rotateSource->initialize();
rotateSource->setProperty("Workspace", toConvert);
rotateSource->setProperty("Angle", thetaInDeg.get());
rotateSource->setProperty("Angle", rotationTheta);
rotateSource->execute();
}

// Always convert units.
auto convertUnits = this->createChildAlgorithm("ConvertUnits");
convertUnits->initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,68 @@

#include <QVariant>

namespace MantidQt
{
namespace CustomInterfaces
{
/** @class IReflPresenter
namespace MantidQt {
namespace CustomInterfaces {
/** @class IReflPresenter
IReflPresenter is an interface which defines the functions any reflectometry interface presenter needs to support.
IReflPresenter is an interface which defines the functions any reflectometry
interface presenter needs to support.
Copyright &copy; 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
Copyright &copy; 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
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 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.
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/>.
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 IReflPresenter
{
public:
virtual ~IReflPresenter() {};
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class IReflPresenter {
public:
virtual ~IReflPresenter(){};

enum Flag
{
SaveFlag,
SaveAsFlag,
AppendRowFlag,
PrependRowFlag,
DeleteRowFlag,
ProcessFlag,
GroupRowsFlag,
OpenTableFlag,
NewTableFlag,
TableUpdatedFlag,
ExpandSelectionFlag,
OptionsDialogFlag,
ClearSelectedFlag,
CopySelectedFlag,
CutSelectedFlag,
PasteSelectedFlag,
SearchFlag,
TransferFlag,
ImportTableFlag,
ExportTableFlag,
PlotRowFlag,
PlotGroupFlag
};
enum Flag {
SaveFlag,
SaveAsFlag,
AppendRowFlag,
PrependRowFlag,
DeleteRowFlag,
ProcessFlag,
GroupRowsFlag,
OpenTableFlag,
NewTableFlag,
TableUpdatedFlag,
ExpandSelectionFlag,
OptionsDialogFlag,
ClearSelectedFlag,
CopySelectedFlag,
CutSelectedFlag,
PasteSelectedFlag,
SearchFlag,
TransferFlag,
ImportTableFlag,
ExportTableFlag,
PlotRowFlag,
PlotGroupFlag
};

//Tell the presenter something happened
virtual void notify(IReflPresenter::Flag flag) = 0;
virtual const std::map<std::string,QVariant>& options() const = 0;
virtual void setOptions(const std::map<std::string,QVariant>& options) = 0;
};
}
// Tell the presenter something happened
virtual void notify(IReflPresenter::Flag flag) = 0;
virtual const std::map<std::string, QVariant> &options() const = 0;
virtual void setOptions(const std::map<std::string, QVariant> &options) = 0;
};
}
#endif
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ 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>
*/
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport QtReflMainView : public MantidQt::API::UserSubWindow,
public ReflMainView,
public ProgressableView {
Expand Down Expand Up @@ -158,4 +158,4 @@ private slots:
} // namespace Mantid
} // namespace CustomInterfaces

#endif /* MANTID_CUSTOMINTERFACES_QTREFLMAINVIEW_H_ */
#endif /* MANTID_CUSTOMINTERFACES_QTREFLMAINVIEW_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ class DLLExport ReflMainView {
};
}
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ class MANTIDQT_CUSTOMINTERFACES_DLL ReflMainViewPresenter
};
}
}
#endif
#endif
34 changes: 17 additions & 17 deletions MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ void QtReflMainView::setModel(QString name) {
}

/**
* Set all possible tranfer methods
* @param methods : All possible transfer methods.
*/
* Set all possible tranfer methods
* @param methods : All possible transfer methods.
*/
void QtReflMainView::setTransferMethods(const std::set<std::string> &methods) {
for (auto method = methods.begin(); method != methods.end(); ++method) {
ui.comboTransferMethod->addItem((*method).c_str());
Expand Down Expand Up @@ -498,9 +498,9 @@ std::string QtReflMainView::requestNotebookPath() {
}

/**
Save settings
@param options : map of user options to save
*/
Save settings
@param options : map of user options to save
*/
void QtReflMainView::saveSettings(
const std::map<std::string, QVariant> &options) {
QSettings settings;
Expand All @@ -511,9 +511,9 @@ void QtReflMainView::saveSettings(
}

/**
Load settings
@param options : map of user options to load into
*/
Load settings
@param options : map of user options to load into
*/
void QtReflMainView::loadSettings(std::map<std::string, QVariant> &options) {
QSettings settings;
settings.beginGroup(ReflSettingsGroup);
Expand Down Expand Up @@ -559,9 +559,9 @@ void QtReflMainView::setProgress(int progress) {
}

/**
Get status of checkbox which determines whether an ipython notebook is produced
@return true if a notebook should be output on process, false otherwise
*/
Get status of checkbox which determines whether an ipython notebook is produced
@return true if a notebook should be output on process, false otherwise
*/
bool QtReflMainView::getEnableNotebook() {
return ui.checkEnableNotebook->isChecked();
}
Expand Down Expand Up @@ -698,16 +698,16 @@ std::string QtReflMainView::getSearchString() const {
}

/**
* Clear the progress
*/
* Clear the progress
*/
void QtReflMainView::clearProgress() { ui.progressBar->reset(); }

/**
* @return the transfer method selected.
*/
* @return the transfer method selected.
*/
std::string QtReflMainView::getTransferMethod() const {
return ui.comboTransferMethod->currentText().toStdString();
}

} // namespace CustomInterfaces
} // namespace Mantid
} // namespace Mantid

0 comments on commit 34a24f9

Please sign in to comment.