25using namespace Kernel;
27using namespace DataObjects;
28using namespace Geometry;
33 auto wsValidator = std::make_shared<WorkspaceUnitValidator>(
"DeltaE");
37 "Name of the input workspace");
40 "Name of the output workspace, can be the same as the input");
42 std::vector<std::string> propOptions{
"Direct",
"Indirect"};
43 this->
declareProperty(
"EMode",
"Direct", std::make_shared<StringListValidator>(propOptions),
44 "The energy mode (default: Direct)");
45 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
46 mustBePositive->setLower(0.0);
48 "Value of fixed energy in meV : EI (EMode=Direct) or "
49 "EF (EMode=Indirect) .");
59 if (eventW !=
nullptr) {
66 if (outputWS != inputWS) {
67 outputWS = inputWS->clone();
70 const size_t size = inputWS->blocksize();
72 const auto numberOfSpectra =
static_cast<int>(inputWS->size() / size);
74 bool negativeEnergyWarning =
false;
80 if (emodeStr ==
"Direct") {
82 if (inputWS->run().hasProperty(
"Ei")) {
83 efixedProp = inputWS->run().getPropertyValueAsType<
double>(
"Ei");
84 g_log.
debug() <<
"Using stored Ei value " << efixedProp <<
"\n";
86 throw std::invalid_argument(
"No Ei value has been set or stored within the run information.");
98 const auto &spectrumInfo = inputWS->spectrumInfo();
101 for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i) {
106 if (emodeStr ==
"Indirect") {
111 else if (spectrumInfo.hasUniqueDetector(i)) {
119 auto &yOut = outputWS->mutableY(i);
120 auto &eOut = outputWS->mutableE(i);
121 const auto &xIn = inputWS->points(i);
122 auto &yIn = inputWS->y(i);
123 auto &eIn = inputWS->e(i);
125 outputWS->setSharedX(i, inputWS->sharedX(i));
126 for (
unsigned int j = 0; j < size; ++j) {
127 const double deltaE = xIn[j];
130 double kioverkf = 1.;
131 if (emodeStr ==
"Direct")
143 if ((Ei <= 0) || (Ef <= 0)) {
146 negativeEnergyWarning =
true;
148 kioverkf = std::sqrt(Ei / Ef);
150 yOut[j] = yIn[j] * kioverkf;
151 eOut[j] = eIn[j] * kioverkf;
158 if (negativeEnergyWarning)
160 if ((negativeEnergyWarning) && (efixedProp ==
EMPTY_DBL()))
174 auto inputWS = std::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
178 if (matrixOutputWS != matrixInputWS) {
179 matrixOutputWS = matrixInputWS->clone();
182 auto outputWS = std::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
188 if (emodeStr ==
"Direct") {
190 if (inputWS->run().hasProperty(
"Ei")) {
191 efixedProp = inputWS->run().getPropertyValueAsType<
double>(
"Ei");
192 g_log.
debug() <<
"Using stored Ei value " << efixedProp <<
"\n";
194 throw std::invalid_argument(
"No Ei value has been set or stored within the run information.");
207 auto numHistograms =
static_cast<int64_t
>(inputWS->getNumberHistograms());
208 const auto &spectrumInfo = inputWS->spectrumInfo();
211 for (int64_t i = 0; i < numHistograms; ++i) {
215 if (emodeStr ==
"Indirect") {
221 }
else if (spectrumInfo.hasUniqueDetector(i)) {
232 auto &evlist = outputWS->getSpectrum(i);
233 switch (evlist.getEventType()) {
254 outputWS->clearMRU();
255 if (inputWS->getNumberEvents() != outputWS->getNumberEvents()) {
256 g_log.
information() <<
"Ef <= 0 or Ei <= 0 for " << inputWS->getNumberEvents() - outputWS->getNumberEvents()
257 <<
" events, out of " << inputWS->getNumberEvents() <<
'\n';
267 typename std::vector<T>::iterator it;
268 for (it = wevector.begin(); it < wevector.end();) {
269 if (emodeStr ==
"Direct")
279 if ((Ei <= 0) || (Ef <= 0)) {
280 it = wevector.erase(it);
282 kioverkf =
static_cast<float>(std::sqrt(Ei / Ef));
283 it->m_weight *= kioverkf;
284 it->m_errorSquared *= kioverkf * kioverkf;
297 const auto &det = spectrumInfo.
detector(i);
300 Efi = par->value<
double>();
301 g_log.
debug() <<
"Detector: " << det.getID() <<
" 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.
const Geometry::IDetector & detector(const size_t index) const
Return a const reference to the detector or detector group of the spectrum with given index.
A property class for workspaces.
void getEfixedFromParameterMap(double &Efi, int64_t i, const Mantid::API::SpectrumInfo &spectrumInfo, const Mantid::Geometry::ParameterMap &pmap)
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.
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::shared_ptr< Parameter > Parameter_sptr
Typedef for the shared pointer.
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.
Generate a tableworkspace to store the calibration results.
@ Input
An input workspace.
@ Output
An output workspace.