Mantid
Loading...
Searching...
No Matches
ApplyInstrumentToPeaks.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
10#include "MantidKernel/Unit.h"
11
12namespace Mantid::Algorithms {
13
14DECLARE_ALGORITHM(ApplyInstrumentToPeaks)
15
16using namespace Mantid::Kernel;
17using namespace Mantid::API;
18using namespace Mantid::DataObjects;
19
21 declareProperty(std::make_unique<WorkspaceProperty<PeaksWorkspace>>("InputWorkspace", "", Direction::Input),
22 "Input peaks workspace.");
23 declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("InstrumentWorkspace", "", Direction::Input,
25 "Workspace from which the instrument will be copied from. If none is provided then the instrument on "
26 "the input workspace is used.");
27 declareProperty(std::make_unique<WorkspaceProperty<PeaksWorkspace>>("OutputWorkspace", "", Direction::Output),
28 "Output peaks workspace.");
29}
30
33 PeaksWorkspace_sptr inputWS = getProperty("InputWorkspace");
34
36 PeaksWorkspace_sptr outputWS = getProperty("OutputWorkspace");
37 if (outputWS != inputWS)
38 outputWS = inputWS->clone();
39
41
42 Workspace_sptr instWS = this->getProperty("InstrumentWorkspace");
43 if (instWS) {
44 ExperimentInfo_sptr ei = std::dynamic_pointer_cast<ExperimentInfo>(instWS);
45 if (!ei)
46 throw std::invalid_argument("Wrong type of workspace");
47 instrument = ei->getInstrument();
48 outputWS->setInstrument(instrument);
49 } else {
50 instrument = outputWS->getInstrument();
51 }
52
53 Units::Energy energyUnit;
54 for (int i = 0; i < outputWS->getNumberPeaks(); ++i) {
55 Peak &peak = outputWS->getPeak(i);
56
57 const auto tof = peak.getTOF();
58
59 peak.setInstrument(instrument);
60 peak.setDetectorID(peak.getDetectorID());
61
62 energyUnit.initialize(peak.getL1(), 0, {{UnitParams::l2, peak.getL2()}});
63 const double energy = energyUnit.singleFromTOF(tof);
64 peak.setInitialEnergy(energy);
65 peak.setFinalEnergy(energy);
66 }
67
68 setProperty("OutputWorkspace", outputWS);
69}
70} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:547
double energy
Definition GetAllEi.cpp:157
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 property class for workspaces.
void exec() override
Virtual method - must be overridden by concrete algorithm.
void init() override
Virtual method - must be overridden by concrete algorithm.
Structure describing a single-crystal peak.
Definition Peak.h:34
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
Definition Peak.cpp:748
void setDetectorID(int id)
Set the detector ID of the pixel at the centre of the peak and look up and cache values related to it...
Definition Peak.cpp:230
int getDetectorID() const override
Get the ID of the detector at the center of the peak
Definition Peak.cpp:289
double getTOF() const override
Calculate the time of flight (in microseconds) of the neutrons for this peak, using the geometry of t...
Definition Peak.cpp:397
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
Definition Peak.cpp:318
void initialize(const double &_l1, const int &_emode, const UnitParametersMap &params)
Initialize the unit to perform conversion using singleToTof() and singleFromTof()
Definition Unit.cpp:133
Energy in milli-electronvolts.
Definition Unit.h:334
double singleFromTOF(const double tof) const override
Convert a single tof value to this unit.
Definition Unit.cpp:476
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
@ Input
An input workspace.
Definition Property.h:54
@ Output
An output workspace.
Definition Property.h:55