Skip to content

Commit

Permalink
refs #8589. Move trans corr to utilising algorithm class.
Browse files Browse the repository at this point in the history
The bit that is actually applying the trans corr is not required in the base class.
  • Loading branch information
OwenArnold committed Dec 13, 2013
1 parent c003547 commit ae7bab4
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 82 deletions.
Expand Up @@ -74,6 +74,16 @@ namespace Mantid
/// Sum spectra.
Mantid::API::MatrixWorkspace_sptr sumSpectraOverRange(API::MatrixWorkspace_sptr inWS, const int startIndex, const int endIndex);

/// Perform a transmission correction on the input IvsLam workspace
API::MatrixWorkspace_sptr transmissonCorrection(API::MatrixWorkspace_sptr IvsLam,
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 );

};

} // namespace Algorithms
Expand Down
Expand Up @@ -94,17 +94,6 @@ namespace Mantid
const OptionalDouble& stitchingEndQ, const OptionalDouble& stitchingStartOverlapQ,
const OptionalDouble& stitchingEndOverlapQ, const double& wavelengthStep);


/// Perform a transmission correction on the input IvsLam workspace
API::MatrixWorkspace_sptr transmissonCorrection(API::MatrixWorkspace_sptr IvsLam,
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
72 changes: 72 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/ReflectometryReductionOne.cpp
Expand Up @@ -48,6 +48,29 @@ namespace Mantid
/*Anonomous namespace */
namespace
{
/**
* Helper non-member function for translating all the workspace indexes in an origin workspace into workspace indexes
* of a host end-point workspace. This is done using spectrum numbers as the intermediate.
*
* This function will throw a runtime error if the specId are not found to exist on the host end-point workspace.
*
* @param originWS : Origin workspace, which provides the original workspace index to spectrum id mapping.
* @param hostWS : Workspace onto which the resulting workspace indexes will be hosted
* @return Remapped wokspace indexes applicable for the host workspace.
*/
ReflectometryWorkflowBase::WorkspaceIndexList createWorkspaceIndexListFromDetectorWorkspace(
MatrixWorkspace_const_sptr originWS, MatrixWorkspace_const_sptr hostWS)
{
auto spectrumMap = originWS->getSpectrumToWorkspaceIndexMap();
ReflectometryWorkflowBase::WorkspaceIndexList translatedIndexList;
for (auto it = spectrumMap.begin(); it != spectrumMap.end(); ++it)
{
specid_t specId = (*it).first;
translatedIndexList.push_back(static_cast<int>(hostWS->getIndexFromSpectrumNumber(specId))); // Could be slow to do it like this.
}
return translatedIndexList;
}


/**
* Helper non-member function
Expand Down Expand Up @@ -467,5 +490,54 @@ namespace Mantid

}


/**
* Perform Transmission Corrections.
* @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 Normalized run workspace by the transmission workspace, which have themselves been converted to Lam, normalized by monitors and possibly stitched together.
*/
MatrixWorkspace_sptr ReflectometryReductionOne::transmissonCorrection(MatrixWorkspace_sptr IvsLam,
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)
{
g_log.debug("Extracting first transmission run workspace indexes from spectra");
const WorkspaceIndexList detectorIndexes = createWorkspaceIndexListFromDetectorWorkspace(IvsLam,
firstTransmissionRun);

// 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();
rebinToWorkspaceAlg->setProperty("WorkspaceToMatch", IvsLam);
rebinToWorkspaceAlg->setProperty("WorkspaceToRebin", denominator);
rebinToWorkspaceAlg->execute();
denominator = rebinToWorkspaceAlg->getProperty("OutputWorkspace");

// Do normalization.
MatrixWorkspace_sptr normalizedIvsLam = IvsLam / denominator;
return normalizedIvsLam;
}

} // namespace Algorithms
} // namespace Mantid
71 changes: 0 additions & 71 deletions Code/Mantid/Framework/Algorithms/src/ReflectometryWorkflowBase.cpp
Expand Up @@ -16,28 +16,6 @@ namespace Mantid
{
namespace
{
/**
* Helper non-member function for translating all the workspace indexes in an origin workspace into workspace indexes
* of a host end-point workspace. This is done using spectrum numbers as the intermediate.
*
* This function will throw a runtime error if the specId are not found to exist on the host end-point workspace.
*
* @param originWS : Origin workspace, which provides the original workspace index to spectrum id mapping.
* @param hostWS : Workspace onto which the resulting workspace indexes will be hosted
* @return Remapped wokspace indexes applicable for the host workspace.
*/
ReflectometryWorkflowBase::WorkspaceIndexList createWorkspaceIndexListFromDetectorWorkspace(
MatrixWorkspace_const_sptr originWS, MatrixWorkspace_const_sptr hostWS)
{
auto spectrumMap = originWS->getSpectrumToWorkspaceIndexMap();
ReflectometryWorkflowBase::WorkspaceIndexList translatedIndexList;
for (auto it = spectrumMap.begin(); it != spectrumMap.end(); ++it)
{
specid_t specId = (*it).first;
translatedIndexList.push_back(static_cast<int>(hostWS->getIndexFromSpectrumNumber(specId))); // Could be slow to do it like this.
}
return translatedIndexList;
}

/**
* Helper method used with the stl to determine whether values are negative
Expand Down Expand Up @@ -576,54 +554,5 @@ namespace Mantid
return transmissionWS;
}


/**
* Perform Transmission Corrections.
* @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 Normalized run workspace by the transmission workspace, which have themselves been converted to Lam, normalized by monitors and possibly stitched together.
*/
MatrixWorkspace_sptr ReflectometryWorkflowBase::transmissonCorrection(MatrixWorkspace_sptr IvsLam,
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)
{
g_log.debug("Extracting first transmission run workspace indexes from spectra");
const WorkspaceIndexList detectorIndexes = createWorkspaceIndexListFromDetectorWorkspace(IvsLam,
firstTransmissionRun);

// 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();
rebinToWorkspaceAlg->setProperty("WorkspaceToMatch", IvsLam);
rebinToWorkspaceAlg->setProperty("WorkspaceToRebin", denominator);
rebinToWorkspaceAlg->execute();
denominator = rebinToWorkspaceAlg->getProperty("OutputWorkspace");

// Do normalization.
MatrixWorkspace_sptr normalizedIvsLam = IvsLam / denominator;
return normalizedIvsLam;
}

} // namespace Algorithms
} // namespace Mantid

0 comments on commit ae7bab4

Please sign in to comment.