24using namespace Kernel;
26using namespace DataObjects;
27using namespace Geometry;
32 auto wsValidator = std::make_shared<WorkspaceUnitValidator>(
"DeltaE");
36 "Name of the input workspace");
39 "Name of the output workspace, can be the same as the input");
41 std::vector<std::string> propOptions{
"Direct",
"Indirect"};
42 this->
declareProperty(
"EMode",
"Direct", std::make_shared<StringListValidator>(propOptions),
43 "The energy mode (default: Direct)");
44 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
45 mustBePositive->setLower(0.0);
47 "Value of fixed energy in meV : EI (EMode=Direct) or "
48 "EF (EMode=Indirect) .");
58 if (eventW !=
nullptr) {
65 if (outputWS != inputWS) {
66 outputWS = inputWS->clone();
69 const size_t size = inputWS->blocksize();
71 const auto numberOfSpectra =
static_cast<int>(inputWS->size() / size);
73 bool negativeEnergyWarning =
false;
79 if (emodeStr ==
"Direct") {
81 if (inputWS->run().hasProperty(
"Ei")) {
82 efixedProp = inputWS->run().getPropertyValueAsType<
double>(
"Ei");
83 g_log.
debug() <<
"Using stored Ei value " << efixedProp <<
"\n";
85 throw std::invalid_argument(
"No Ei value has been set or stored within the run information.");
96 const auto &componentInfo = outputWS->componentInfo();
97 const auto &spectrumInfo = inputWS->spectrumInfo();
100 for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i) {
105 if (emodeStr ==
"Indirect") {
110 else if (spectrumInfo.hasUniqueDetector(i)) {
118 auto &yOut = outputWS->mutableY(i);
119 auto &eOut = outputWS->mutableE(i);
120 const auto &xIn = inputWS->points(i);
121 auto &yIn = inputWS->y(i);
122 auto &eIn = inputWS->e(i);
124 outputWS->setSharedX(i, inputWS->sharedX(i));
125 for (
unsigned int j = 0; j < size; ++j) {
126 const double deltaE = xIn[j];
129 double kioverkf = 1.;
130 if (emodeStr ==
"Direct")
142 if ((Ei <= 0) || (Ef <= 0)) {
145 negativeEnergyWarning =
true;
147 kioverkf = std::sqrt(Ei / Ef);
149 yOut[j] = yIn[j] * kioverkf;
150 eOut[j] = eIn[j] * kioverkf;
157 if (negativeEnergyWarning)
159 if ((negativeEnergyWarning) && (efixedProp ==
EMPTY_DBL()))
173 auto inputWS = std::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
177 if (matrixOutputWS != matrixInputWS) {
178 matrixOutputWS = matrixInputWS->clone();
181 auto outputWS = std::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
187 if (emodeStr ==
"Direct") {
189 if (inputWS->run().hasProperty(
"Ei")) {
190 efixedProp = inputWS->run().getPropertyValueAsType<
double>(
"Ei");
191 g_log.
debug() <<
"Using stored Ei value " << efixedProp <<
"\n";
193 throw std::invalid_argument(
"No Ei value has been set or stored within the run information.");
204 const auto &componentInfo = outputWS->componentInfo();
206 auto numHistograms =
static_cast<int64_t
>(inputWS->getNumberHistograms());
207 const auto &spectrumInfo = inputWS->spectrumInfo();
210 for (int64_t i = 0; i < numHistograms; ++i) {
214 if (emodeStr ==
"Indirect") {
220 }
else if (spectrumInfo.hasUniqueDetector(i)) {
231 auto &evlist = outputWS->getSpectrum(i);
232 switch (evlist.getEventType()) {
253 outputWS->clearMRU();
254 if (inputWS->getNumberEvents() != outputWS->getNumberEvents()) {
255 g_log.
information() <<
"Ef <= 0 or Ei <= 0 for " << inputWS->getNumberEvents() - outputWS->getNumberEvents()
256 <<
" events, out of " << inputWS->getNumberEvents() <<
'\n';
266 typename std::vector<T>::iterator it;
267 for (it = wevector.begin(); it < wevector.end();) {
268 if (emodeStr ==
"Direct")
278 if ((Ei <= 0) || (Ef <= 0)) {
279 it = wevector.erase(it);
281 kioverkf =
static_cast<float>(std::sqrt(Ei / Ef));
282 it->m_weight *= kioverkf;
283 it->m_errorSquared *= kioverkf * kioverkf;
298 if (!eFixed.empty()) {
299 Efi = eFixed.front();
300 g_log.
debug() <<
"Spectrum index: " << i <<
" EFixed: " << Efi <<
"\n";
#define DECLARE_ALGORITHM(classname)
#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.
Helper class for reporting progress from algorithms.
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
bool isMonitor(const size_t index) const
Returns true if the detector(s) associated with the spectrum are monitors.
bool hasUniqueDetector(const size_t index) const
Returns true if the spectrum is associated with exactly one detector.
const SpectrumDefinition & spectrumDefinition(const size_t index) const
Returns a const reference to the SpectrumDefinition of the spectrum.
A property class for workspaces.
void getEfixedFromParameterMap(double &Efi, int64_t i, const Mantid::API::SpectrumInfo &spectrumInfo, const Mantid::Geometry::ComponentInfo &componentInfo)
void execEvent()
Execute CorrectKiKf for event workspaces.
void exec() override
Virtual method - must be overridden by concrete algorithm.
void correctKiKfEventHelper(std::vector< T > &wevector, double efixed, const std::string &emodeStr)
Execute CorrectKiKf for event lists.
void init() override
Initialisation method.
ComponentInfo : Provides a component centric view on to the instrument.
std::vector< double > getNumberParameter(const size_t componentIndex, const std::string &name, bool recursive=true) const
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 information(const std::string &msg)
Logs at information level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
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.