Skip to content

Commit

Permalink
refs #8589. Make transmission runs not needed on base.
Browse files Browse the repository at this point in the history
Make transmission runs can be private to the creation algorithm now that the workflow algorithm is calling the creational algorithm rather than using a shared method on the base class.
  • Loading branch information
OwenArnold committed Dec 13, 2013
1 parent 6f05e9c commit e63d50f
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 148 deletions.
Expand Up @@ -6,51 +6,60 @@

namespace Mantid
{
namespace Algorithms
{
namespace Algorithms
{

/** CreateTransmissionWorkspace : Create a transmission run workspace in Wavelength given one or more TOF workspaces
Copyright © 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
/** CreateTransmissionWorkspace : Create a transmission run workspace in Wavelength given one or more TOF workspaces
This file is part of Mantid.
Copyright © 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
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.
This file is part of Mantid.
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 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
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.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport CreateTransmissionWorkspace : public ReflectometryWorkflowBase
{
public:
CreateTransmissionWorkspace();
virtual ~CreateTransmissionWorkspace();

virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;
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 CreateTransmissionWorkspace: public ReflectometryWorkflowBase
{
public:
CreateTransmissionWorkspace();
virtual ~CreateTransmissionWorkspace();

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

private:
virtual void initDocs();
void init();
void exec();
private:

/// Make a transmission correction workspace
API::MatrixWorkspace_sptr makeTransmissionCorrection(const WorkspaceIndexList& detectorIndexes,
const MinMax& wavelengthInterval, const MinMax& wavelengthMonitorBackgroundInterval,
const MinMax& wavelengthMonitorIntegrationInterval, const int& i0MonitorIndex,
API::MatrixWorkspace_sptr firstTransmissionRun,
OptionalMatrixWorkspace_sptr secondTransmissionRun, const OptionalDouble& stitchingStartQ,
const OptionalDouble& stitchingDeltaQ, const OptionalDouble& stitchingEndQ,
const OptionalDouble& stitchingStartOverlapQ, const OptionalDouble& stitchingEndOverlapQ,
const double& wavelengthStep);

};
virtual void initDocs();
void init();
void exec();

};

} // namespace Algorithms
} // namespace Algorithms
} // namespace Mantid

#endif /* MANTID_ALGORITHMS_CREATETRANSMISSIONWORKSPACE_H_ */
Expand Up @@ -84,16 +84,6 @@ namespace Mantid
/// Init common stitching inputs
void initStitchingInputs();

/// Make a transmission correction workspace
API::MatrixWorkspace_sptr makeTransmissionCorrection(
const WorkspaceIndexList& detectorIndexes, const MinMax& wavelengthInterval,
const MinMax& wavelengthMonitorBackgroundInterval,
const MinMax& wavelengthMonitorIntegrationInterval, const int& i0MonitorIndex,
API::MatrixWorkspace_sptr firstTransmissionRun, OptionalMatrixWorkspace_sptr secondTransmissionRun,
const OptionalDouble& stitchingStartQ, const OptionalDouble& stitchingDeltaQ,
const OptionalDouble& stitchingEndQ, const OptionalDouble& stitchingStartOverlapQ,
const OptionalDouble& stitchingEndOverlapQ, const double& wavelengthStep);

private:

/// Validate the transmission correction property inputs
Expand Down
Expand Up @@ -12,6 +12,7 @@
#include "MantidKernel/RebinParamsValidator.h"
#include "MantidKernel/BoundedValidator.h"
#include <boost/make_shared.hpp>
#include <boost/assign/list_of.hpp>

using namespace Mantid::Kernel;
using namespace Mantid::API;
Expand Down Expand Up @@ -145,5 +146,102 @@ namespace Mantid
setProperty("OutputWorkspace", outWS);
}



/**
* Create a transmission corrections workspace utilising one or two workspaces.
*
* Input workspaces are in TOF. These are converted to lambda, normalized and stitched together (if two given).
*
* @param IvsLam : Run workspace which is to be normalized by the results of the transmission corrections.
* @param wavelengthInterval : Wavelength interval for the run workspace.
* @param wavelengthMonitorBackgroundInterval : Wavelength interval for the monitor background
* @param wavelengthMonitorIntegrationInterval : Wavelength interval for the monitor integration
* @param i0MonitorIndex : Monitor index for the I0 monitor
* @param firstTransmissionRun : The first transmission run
* @param secondTransmissionRun : The second transmission run (optional)
* @param stitchingStartQ : Stitching start Q (optional but dependent on secondTransmissionRun)
* @param stitchingDeltaQ : Stitching delta Q (optional but dependent on secondTransmissionRun)
* @param stitchingEndQ : Stitching end Q (optional but dependent on secondTransmissionRun)
* @param stitchingStartOverlapQ : Stitching start Q overlap (optional but dependent on secondTransmissionRun)
* @param stitchingEndOverlapQ : Stitching end Q overlap (optional but dependent on secondTransmissionRun)
* @param wavelengthStep : Step in angstroms for rebinning for workspaces converted into wavelength.
* @return A transmission workspace in Wavelength units.
*/
MatrixWorkspace_sptr CreateTransmissionWorkspace::makeTransmissionCorrection(
const WorkspaceIndexList& detectorIndexes,
const MinMax& wavelengthInterval,
const MinMax& wavelengthMonitorBackgroundInterval,
const MinMax& wavelengthMonitorIntegrationInterval,
const int& i0MonitorIndex,
MatrixWorkspace_sptr firstTransmissionRun,
OptionalMatrixWorkspace_sptr secondTransmissionRun,
const OptionalDouble& stitchingStartQ,
const OptionalDouble& stitchingDeltaQ,
const OptionalDouble& stitchingEndQ,
const OptionalDouble& stitchingStartOverlapQ,
const OptionalDouble& stitchingEndOverlapQ,
const double& wavelengthStep)
{
auto trans1InLam = toLam(firstTransmissionRun, detectorIndexes, i0MonitorIndex, wavelengthInterval,
wavelengthMonitorBackgroundInterval, wavelengthStep);
MatrixWorkspace_sptr trans1Detector = trans1InLam.get<0>();
MatrixWorkspace_sptr trans1Monitor = trans1InLam.get<1>();

// Monitor integration ... can this happen inside the toLam routine?
auto integrationAlg = this->createChildAlgorithm("Integration");
integrationAlg->initialize();
integrationAlg->setProperty("InputWorkspace", trans1Monitor);
integrationAlg->setProperty("RangeLower", wavelengthMonitorIntegrationInterval.get<0>());
integrationAlg->setProperty("RangeUpper", wavelengthMonitorIntegrationInterval.get<1>());
integrationAlg->execute();
trans1Monitor = integrationAlg->getProperty("OutputWorkspace");

MatrixWorkspace_sptr transmissionWS = trans1Detector / trans1Monitor;

if (secondTransmissionRun.is_initialized())
{
auto transRun2 = secondTransmissionRun.get();
g_log.debug("Extracting second transmission run workspace indexes from spectra");

auto trans2InLam = toLam(transRun2, detectorIndexes, i0MonitorIndex, wavelengthInterval,
wavelengthMonitorBackgroundInterval, wavelengthStep);

// Unpack the conversion results.
MatrixWorkspace_sptr trans2Detector = trans2InLam.get<0>();
MatrixWorkspace_sptr trans2Monitor = trans2InLam.get<1>();

// Monitor integration ... can this happen inside the toLam routine?
auto integrationAlg = this->createChildAlgorithm("Integration");
integrationAlg->initialize();
integrationAlg->setProperty("InputWorkspace", trans2Monitor);
integrationAlg->setProperty("RangeLower", wavelengthMonitorIntegrationInterval.get<0>());
integrationAlg->setProperty("RangeUpper", wavelengthMonitorIntegrationInterval.get<1>());
integrationAlg->execute();
trans2Monitor = integrationAlg->getProperty("OutputWorkspace");

MatrixWorkspace_sptr normalizedTrans2 = trans2Detector / trans2Monitor;

// Stitch the results.
auto stitch1DAlg = this->createChildAlgorithm("Stitch1D");
stitch1DAlg->initialize();
AnalysisDataService::Instance().addOrReplace("transmissionWS", transmissionWS);
AnalysisDataService::Instance().addOrReplace("normalizedTrans2", normalizedTrans2);
stitch1DAlg->setProperty("LHSWorkspace", transmissionWS);
stitch1DAlg->setProperty("RHSWorkspace", normalizedTrans2);
stitch1DAlg->setProperty("StartOverlap", stitchingStartOverlapQ.get());
stitch1DAlg->setProperty("EndOverlap", stitchingEndOverlapQ.get());
const std::vector<double> params = boost::assign::list_of(stitchingStartQ.get())(
stitchingDeltaQ.get())(stitchingEndQ.get()).convert_to_container<std::vector<double> >();
stitch1DAlg->setProperty("Params", params);
stitch1DAlg->execute();
transmissionWS = stitch1DAlg->getProperty("OutputWorkspace");
AnalysisDataService::Instance().remove("transmissionWS");
AnalysisDataService::Instance().remove("normalizedTrans2");
}

return transmissionWS;
}

} // namespace Algorithms
} // namespace Mantid
Expand Up @@ -544,14 +544,6 @@ namespace Mantid
alg->execute();
MatrixWorkspace_sptr denominator = alg->getProperty("OutputWorkspace");

/*
// Make the transmission run.
MatrixWorkspace_sptr denominator = makeTransmissionCorrection(detectorIndexes, wavelengthInterval,
wavelengthMonitorBackgroundInterval, wavelengthMonitorIntegrationInterval, i0MonitorIndex,
firstTransmissionRun, secondTransmissionRun, stitchingStartQ, stitchingDeltaQ, stitchingEndQ,
stitchingStartOverlapQ, stitchingEndOverlapQ, wavelengthStep);
*/

// Rebin the transmission run to be the same as the input.
auto rebinToWorkspaceAlg = this->createChildAlgorithm("RebinToWorkspace");
rebinToWorkspaceAlg->initialize();
Expand Down
96 changes: 0 additions & 96 deletions Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp
Expand Up @@ -458,101 +458,5 @@ namespace Mantid
return DetectorMonitorWorkspacePair(detectorWS, monitorWS);
}


/**
* Create a transmission corrections workspace utilising one or two workspaces.
*
* Input workspaces are in TOF. These are converted to lambda, normalized and stitched together (if two given).
*
* @param IvsLam : Run workspace which is to be normalized by the results of the transmission corrections.
* @param wavelengthInterval : Wavelength interval for the run workspace.
* @param wavelengthMonitorBackgroundInterval : Wavelength interval for the monitor background
* @param wavelengthMonitorIntegrationInterval : Wavelength interval for the monitor integration
* @param i0MonitorIndex : Monitor index for the I0 monitor
* @param firstTransmissionRun : The first transmission run
* @param secondTransmissionRun : The second transmission run (optional)
* @param stitchingStartQ : Stitching start Q (optional but dependent on secondTransmissionRun)
* @param stitchingDeltaQ : Stitching delta Q (optional but dependent on secondTransmissionRun)
* @param stitchingEndQ : Stitching end Q (optional but dependent on secondTransmissionRun)
* @param stitchingStartOverlapQ : Stitching start Q overlap (optional but dependent on secondTransmissionRun)
* @param stitchingEndOverlapQ : Stitching end Q overlap (optional but dependent on secondTransmissionRun)
* @param wavelengthStep : Step in angstroms for rebinning for workspaces converted into wavelength.
* @return A transmission workspace in Wavelength units.
*/
MatrixWorkspace_sptr ReflectometryWorkflowBase::makeTransmissionCorrection(
const WorkspaceIndexList& detectorIndexes,
const MinMax& wavelengthInterval,
const MinMax& wavelengthMonitorBackgroundInterval,
const MinMax& wavelengthMonitorIntegrationInterval,
const int& i0MonitorIndex,
MatrixWorkspace_sptr firstTransmissionRun,
OptionalMatrixWorkspace_sptr secondTransmissionRun,
const OptionalDouble& stitchingStartQ,
const OptionalDouble& stitchingDeltaQ,
const OptionalDouble& stitchingEndQ,
const OptionalDouble& stitchingStartOverlapQ,
const OptionalDouble& stitchingEndOverlapQ,
const double& wavelengthStep)
{
auto trans1InLam = toLam(firstTransmissionRun, detectorIndexes, i0MonitorIndex, wavelengthInterval,
wavelengthMonitorBackgroundInterval, wavelengthStep);
MatrixWorkspace_sptr trans1Detector = trans1InLam.get<0>();
MatrixWorkspace_sptr trans1Monitor = trans1InLam.get<1>();

// Monitor integration ... can this happen inside the toLam routine?
auto integrationAlg = this->createChildAlgorithm("Integration");
integrationAlg->initialize();
integrationAlg->setProperty("InputWorkspace", trans1Monitor);
integrationAlg->setProperty("RangeLower", wavelengthMonitorIntegrationInterval.get<0>());
integrationAlg->setProperty("RangeUpper", wavelengthMonitorIntegrationInterval.get<1>());
integrationAlg->execute();
trans1Monitor = integrationAlg->getProperty("OutputWorkspace");

MatrixWorkspace_sptr transmissionWS = trans1Detector / trans1Monitor;

if (secondTransmissionRun.is_initialized())
{
auto transRun2 = secondTransmissionRun.get();
g_log.debug("Extracting second transmission run workspace indexes from spectra");

auto trans2InLam = toLam(transRun2, detectorIndexes, i0MonitorIndex, wavelengthInterval,
wavelengthMonitorBackgroundInterval, wavelengthStep);

// Unpack the conversion results.
MatrixWorkspace_sptr trans2Detector = trans2InLam.get<0>();
MatrixWorkspace_sptr trans2Monitor = trans2InLam.get<1>();

// Monitor integration ... can this happen inside the toLam routine?
auto integrationAlg = this->createChildAlgorithm("Integration");
integrationAlg->initialize();
integrationAlg->setProperty("InputWorkspace", trans2Monitor);
integrationAlg->setProperty("RangeLower", wavelengthMonitorIntegrationInterval.get<0>());
integrationAlg->setProperty("RangeUpper", wavelengthMonitorIntegrationInterval.get<1>());
integrationAlg->execute();
trans2Monitor = integrationAlg->getProperty("OutputWorkspace");

MatrixWorkspace_sptr normalizedTrans2 = trans2Detector / trans2Monitor;

// Stitch the results.
auto stitch1DAlg = this->createChildAlgorithm("Stitch1D");
stitch1DAlg->initialize();
AnalysisDataService::Instance().addOrReplace("transmissionWS", transmissionWS);
AnalysisDataService::Instance().addOrReplace("normalizedTrans2", normalizedTrans2);
stitch1DAlg->setProperty("LHSWorkspace", transmissionWS);
stitch1DAlg->setProperty("RHSWorkspace", normalizedTrans2);
stitch1DAlg->setProperty("StartOverlap", stitchingStartOverlapQ.get());
stitch1DAlg->setProperty("EndOverlap", stitchingEndOverlapQ.get());
const std::vector<double> params = boost::assign::list_of(stitchingStartQ.get())(
stitchingDeltaQ.get())(stitchingEndQ.get()).convert_to_container<std::vector<double> >();
stitch1DAlg->setProperty("Params", params);
stitch1DAlg->execute();
transmissionWS = stitch1DAlg->getProperty("OutputWorkspace");
AnalysisDataService::Instance().remove("transmissionWS");
AnalysisDataService::Instance().remove("normalizedTrans2");
}

return transmissionWS;
}

} // namespace Algorithms
} // namespace Mantid

0 comments on commit e63d50f

Please sign in to comment.