22using namespace Kernel;
24using namespace Geometry;
37 return "CorrectionFunctions\\EfficiencyCorrections;Inelastic\\Corrections";
43 auto val = std::make_shared<CompositeValidator>();
49 "The workspace to correct for detector efficiency");
51 "The name of the workspace in which to store the result.");
52 auto checkEi = std::make_shared<BoundedValidator<double>>();
53 checkEi->setLower(0.0);
63 const size_t numberOfChannels = this->
m_inputWS->blocksize();
65 const auto numberOfSpectra =
static_cast<int>(this->
m_inputWS->size() / numberOfChannels);
67 auto numberOfSpectra_i =
static_cast<int64_t
>(numberOfSpectra);
71 for (int64_t i = 0; i < numberOfSpectra_i; ++i) {
78 const double eff0 =
evaluate(parser);
81 prog.
report(
"Detector Efficiency correction...");
99 const mu::Parser &parser) {
105 for (
size_t i = 0; i < xIn.size(); ++i) {
107 const double eff =
evaluate(parser);
108 const double corr = eff / eff0;
109 yOut[i] = yIn[i] / corr;
110 eOut[i] = eIn[i] / corr;
122 return parser.Eval();
123 }
catch (mu::Parser::exception_type &e) {
125 "Error calculating formula from string. Muparser error message is: " + e.GetMsg());
142 const std::string formulaParamName(
"formula_eff");
143 const auto ¶mMap =
m_inputWS->constInstrumentParameters();
144 auto det =
m_inputWS->getDetector(workspaceIndex);
145 auto param = paramMap.getRecursive(det.get(), formulaParamName,
"string");
148 det->getFullName() +
"' in the instrument definition.");
150 const auto ret = param->asString();
151 g_log.
debug() <<
"Found formula for workspace index " << workspaceIndex <<
": " << ret <<
"\n";
169 m_outputWS.reset(Mantid::DataObjects::create<DataObjects::Workspace2D>(*m_inputWS).release());
179 throw std::invalid_argument(
"No Ei value has been set or stored within the run information.");
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
A validator which checks that a workspace has a valid instrument.
Helper class for reporting progress from algorithms.
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
DetectorEfficiencyCorUser :
double m_Ei
stores the user selected value for incidient energy of the neutrons
void exec() override
Execute the algorithm.
mu::Parser generateParser(const std::string &formula, double *e) const
const std::string category() const override
Algorithm's category for identification.
API::MatrixWorkspace_sptr m_outputWS
The output workspace, maybe the same as the input one.
void retrieveProperties()
Loads and checks the values passed to the algorithm.
double evaluate(const mu::Parser &parser) const
Calculate the value of a formula parsed by muParser.
API::MatrixWorkspace_const_sptr m_inputWS
The user selected (input) workspace.
void init() override
Initialize the algorithm's properties.
int version() const override
Algorithm's version for identification.
void correctHistogram(const size_t index, const double eff0, double &e, const mu::Parser &parser)
Apply efficiency corrections to a histogram in the output workspace.
std::string retrieveFormula(const size_t workspaceIndex)
Returns the efficiency correction formula associated to a detector.
Exception for errors associated with the instrument definition.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Base class for properties.
virtual std::string value() const =0
Returns the value of the property as a string.
int convert(const std::string &A, T &out)
Convert a string into a number.
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.