Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slit calculator #197

Merged
merged 9 commits into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set ( SRC_FILES
src/CalculateEfficiency.cpp
src/CalculateFlatBackground.cpp
src/CalculateResolution.cpp
src/CalculateSlits.cpp
src/CalculateTransmission.cpp
src/CalculateTransmissionBeamSpreader.cpp
src/CalculateZscore.cpp
Expand Down Expand Up @@ -277,6 +278,7 @@ set ( INC_FILES
inc/MantidAlgorithms/CalculateEfficiency.h
inc/MantidAlgorithms/CalculateFlatBackground.h
inc/MantidAlgorithms/CalculateResolution.h
inc/MantidAlgorithms/CalculateSlits.h
inc/MantidAlgorithms/CalculateTransmission.h
inc/MantidAlgorithms/CalculateTransmissionBeamSpreader.h
inc/MantidAlgorithms/CalculateZscore.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef MANTID_ALGORITHMS_CALCULATESLITS_H_
#define MANTID_ALGORITHMS_CALCULATESLITS_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/DataProcessorAlgorithm.h"
#include <boost/optional.hpp>

namespace Mantid {
namespace Algorithms {

/** CalculateSlits

Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source

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 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/>.

File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

class DLLExport CalculateSlits : public API::DataProcessorAlgorithm {
public:
CalculateSlits();
virtual ~CalculateSlits();

virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;
virtual const std::string summary() const;

private:
void init();
void exec();
};

} // namespace Algorithms
} // namespace Mantid

#endif /* MANTID_ALGORITHMS_CALCULATESLITS_H_ */
125 changes: 125 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/CalculateSlits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include "MantidAlgorithms/CalculateSlits.h"

#include <boost/shared_ptr.hpp>
#include <math.h>

namespace Mantid {
namespace Algorithms {

using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::Kernel;

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CalculateSlits)

//----------------------------------------------------------------------------------------------
/** Constructor
*/
CalculateSlits::CalculateSlits() {}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
CalculateSlits::~CalculateSlits() {}

//----------------------------------------------------------------------------------------------

/// Algorithm's name for identification. @see Algorithm::name
const std::string CalculateSlits::name() const {
return "CalculateSlits";
};

/// Algorithm's version for identification. @see Algorithm::version
int CalculateSlits::version() const { return 1; };

/// Algorithm's category for identification. @see Algorithm::category
const std::string CalculateSlits::category() const {
return "Reflectometry\\ISIS";
}

/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string CalculateSlits::summary() const {
return "Calculates appropriate slit widths for reflectometry instruments.";
};

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void CalculateSlits::init() {
declareProperty("Slit1Slit2", Mantid::EMPTY_DBL(),
"Distance between slit 1 and slit 2 in mm");
declareProperty("Slit2SA", Mantid::EMPTY_DBL(), "Offset in the beam direction in mm");
declareProperty("Resolution", Mantid::EMPTY_DBL(), "Resolution");
declareProperty("Footprint", Mantid::EMPTY_DBL(), "Footprint in mm");
declareProperty("Angle", Mantid::EMPTY_DBL(), "Angle in degrees");

declareProperty("Slit1", Mantid::EMPTY_DBL(), "Slit 1 width in mm",
Direction::Output);
declareProperty("Slit2", Mantid::EMPTY_DBL(), "Slit 2 width in mm",
Direction::Output);
}

//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void CalculateSlits::exec() {
const double res = getProperty("Resolution");
const double fp = getProperty("Footprint");
const double angleDeg = getProperty("Angle");
const double s1s2 = getProperty("Slit1Slit2");
const double s2sa = getProperty("Slit2SA");


/*
|←----d-----→|
_ _
_ _ _-¯ | ↑
↑ | ¯-_ _-¯ | |
S₂ | (Θ_X_Θ) | S₁ ←---beam---
↓ |_-¯ ¯-_ | |
¯ ¯-_| ↓
¯
_ _
_-¯ | ↑
_-¯ | |
_-¯ _| | ½S₀
_-¯α) | | ↓
¯¯¯¯¯¯¯¯¯¯¯¯ ¯
|←----d-----→|

For the purposes of these diagrams, Θ has
already been multiplied by the resolution.

α = ½Θ
t = tan(α)
r = resolution
f = footprint (???)
u = unknown dimension

S₀ = S₁ + S₂
= 2•d•t

S₁ = 2•d•t - S₂
= 2•d•t - f•sin(α/r) + 2•u•t
= 2•(d+u)•t - f•sin(α/r)

S₂ = f•sin(α/r) - 2•u•t

sin(α/r) is opp/hyp of the full angle, without the resolution coefficient
if f is the hypotenuse of a triangle constructed from the full angle
then f•sin(α/r) is the length of the side opposite the angle
*/

//Convert angle to radians for our calculations
const double a = angleDeg * M_PI / 180.0;

const double s2 = (fp * sin(a)) - (2 * s2sa * tan(res * a));
const double s1 = (2 * s1s2 * tan(res * a)) - s2;

setProperty("Slit1", s1);
setProperty("Slit2", s2);
}

} // namespace Algorithms
} // namespace Mantid
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "MantidQtCustomInterfaces/IReflPresenter.h"
#include "MantidQtCustomInterfaces/ReflSearchModel.h"
#include "MantidQtCustomInterfaces/QReflTableModel.h"
#include "MantidQtMantidWidgets/SlitCalculator.h"
#include <boost/scoped_ptr.hpp>
#include <QSignalMapper>
#include "ui_ReflMainWidget.h"
Expand Down Expand Up @@ -100,6 +101,7 @@ namespace MantidQt
//the workspace the user selected to open
std::string m_toOpen;
QSignalMapper* m_openMap;
MantidWidgets::SlitCalculator* m_calculator;

private slots:
void on_actionNewTable_triggered();
Expand All @@ -123,6 +125,7 @@ namespace MantidQt
void on_actionHelp_triggered();
void on_actionPlotRow_triggered();
void on_actionPlotGroup_triggered();
void on_actionSlitCalculator_triggered();

void on_comboSearchInstrument_currentIndexChanged(int index);
void on_comboProcessInstrument_currentIndexChanged(int index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@
<addaction name="actionImportTable"/>
<addaction name="actionExportTable"/>
<addaction name="separator"/>
<addaction name="actionSlitCalculator"/>
<addaction name="separator"/>
<addaction name="actionOptionsDialog"/>
</widget>
<widget class="QMenu" name="menuRows">
Expand Down Expand Up @@ -685,6 +687,15 @@
<string>Creates a plot of the stitched IvsQ workspaces produced by any groups any selected rows are in.</string>
</property>
</action>
<action name="actionSlitCalculator">
<property name="icon">
<iconset resource="../../../../MantidPlot/icons/icons.qrc">
<normaloff>:/param_range_btn.png</normaloff>:/param_range_btn.png</iconset>
</property>
<property name="text">
<string>Slit Calculator</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>comboSearchInstrument</tabstop>
Expand Down
10 changes: 9 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/QtReflMainView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace MantidQt
//----------------------------------------------------------------------------------------------
/** Constructor
*/
QtReflMainView::QtReflMainView(QWidget *parent) : UserSubWindow(parent), m_openMap(new QSignalMapper(this))
QtReflMainView::QtReflMainView(QWidget *parent) : UserSubWindow(parent), m_openMap(new QSignalMapper(this)), m_calculator(new MantidWidgets::SlitCalculator(this))
{
}

Expand Down Expand Up @@ -294,6 +294,14 @@ namespace MantidQt
m_presenter->notify(IReflPresenter::PlotGroupFlag);
}

/**
This slot shows the slit calculator
*/
void QtReflMainView::on_actionSlitCalculator_triggered()
{
m_calculator->show();
}

/**
This slot notifies the presenter that the table has been updated/changed by the user
*/
Expand Down