Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*WIKI*
*WIKI*/
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/AlignAndFocusPowder.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidDataHandling/LoadCalFile.h"
#include "MantidDataObjects/GroupingWorkspace.h"
#include "MantidDataObjects/MaskWorkspace.h"
#include "MantidDataObjects/OffsetsWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/System.h"
using Mantid::Geometry::Instrument_const_sptr;
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
namespace Mantid
{
namespace Algorithms
{
// Register the class into the algorithm factory
DECLARE_ALGORITHM(AlignAndFocusPowder)
/// Constructor
AlignAndFocusPowder::AlignAndFocusPowder() : API::Algorithm(), API::DeprecatedAlgorithm()
{
this->useAlgorithm("AlignAndFocusPowder version 2");
}
/// Sets documentation strings for this algorithm
void AlignAndFocusPowder::initDocs()
{
this->setWikiSummary("Algorithm to focus powder diffraction data into a number of histograms according to a grouping scheme defined in a [[CalFile]]. ");
this->setOptionalMessage("Algorithm to focus powder diffraction data into a number of histograms according to a grouping scheme defined in a CalFile.");
}
using namespace Kernel;
using API::WorkspaceProperty;
using API::MatrixWorkspace_sptr;
using API::MatrixWorkspace;
using API::FileProperty;
/** Initialisation method. Declares properties to be used in algorithm.
*
*/
void AlignAndFocusPowder::init()
{
declareProperty(
new WorkspaceProperty<MatrixWorkspace>("InputWorkspace","",Direction::Input),
"The input workspace" );
declareProperty(
new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace","",Direction::Output),
"The result of diffraction focussing of InputWorkspace" );
declareProperty("Params","","The binning parameters");
declareProperty(new FileProperty("CalFileName", "", FileProperty::OptionalLoad, ".cal"),
"The name of the CalFile with offset, masking, and grouping data" );
declareProperty(new WorkspaceProperty<GroupingWorkspace>("GroupingWorkspace","",Direction::Input, PropertyMode::Optional),
"Optional: An GroupingWorkspace workspace giving the grouping info.");
declareProperty(new WorkspaceProperty<OffsetsWorkspace>("OffsetsWorkspace","",Direction::Input, PropertyMode::Optional),
"Optional: An OffsetsWorkspace workspace giving the detector calibration values.");
declareProperty(new WorkspaceProperty<MatrixWorkspace>("MaskWorkspace","",Direction::Input, PropertyMode::Optional),
"Optional: An Workspace workspace giving which detectors are masked.");
}
/** Executes the algorithm
*
* @throw Exception::FileError If the grouping file cannot be opened or read successfully
* @throw runtime_error If unable to run one of the sub-algorithms successfully
*/
void AlignAndFocusPowder::exec()
{
// retrieve the properties
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
std::string calFileName=getProperty("CalFileName");
OffsetsWorkspace_sptr offsetsWS = getProperty("OffsetsWorkspace");
MatrixWorkspace_sptr maskWS = getProperty("MaskWorkspace");
GroupingWorkspace_sptr groupWS = getProperty("GroupingWorkspace");
// Get the input workspace
if ((!offsetsWS || !maskWS || !groupWS) && !calFileName.empty())
{
// Load the .cal file
IAlgorithm_sptr alg = createSubAlgorithm("LoadCalFile");
alg->setPropertyValue("CalFilename", calFileName);
alg->setProperty("InputWorkspace", inputWS);
if(groupWS) alg->setProperty<bool>("MakeGroupingWorkspace", false);
if(offsetsWS) alg->setProperty<bool>("MakeOffsetsWorkspace", false);
if(maskWS)alg->setProperty<bool>("MakeMaskWorkspace", false);
std::string instName = inputWS->getInstrument()->getName();
alg->setProperty<std::string>("WorkspaceName", instName);
alg->executeAsSubAlg();
groupWS = alg->getProperty("OutputGroupingWorkspace");
offsetsWS = alg->getProperty("OutputOffsetsWorkspace");
maskWS = alg->getProperty("OutputMaskWorkspace");
AnalysisDataService::Instance().add(instName+"_group", groupWS);
AnalysisDataService::Instance().add(instName+"_offsets", offsetsWS);
AnalysisDataService::Instance().add(instName+"_mask", maskWS);
}
std::string params = getProperty("Params");
API::IAlgorithm_sptr rebinAlg = createSubAlgorithm("Rebin");
rebinAlg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", inputWS);
rebinAlg->setProperty("Params",params);
rebinAlg->setProperty("PreserveEvents", true);
rebinAlg->executeAsSubAlg();
MatrixWorkspace_sptr outputWS = rebinAlg->getProperty("OutputWorkspace");
setProperty("OutputWorkspace",outputWS);
}
} // namespace Algorithm
} // namespace Mantid