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
11namespace Mantid::Algorithms {
12
13DECLARE_ALGORITHM(ApplyInstrumentToPeaks)
14
15using namespace Mantid::Kernel;
16using namespace Mantid::API;
17using namespace Mantid::DataObjects;
18
20 declareProperty(std::make_unique<WorkspaceProperty<PeaksWorkspace>>("InputWorkspace", "", Direction::Input),
21 "Input peaks workspace.");
22 declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("InstrumentWorkspace", "", Direction::Input,
24 "Workspace from which the instrument will be copied from. If none is provided then the instrument on "
25 "the input workspace is used.");
26 declareProperty(std::make_unique<WorkspaceProperty<PeaksWorkspace>>("OutputWorkspace", "", Direction::Output),
27 "Output peaks workspace.");
28}
29
32 PeaksWorkspace_sptr inputWS = getProperty("InputWorkspace");
33
35 PeaksWorkspace_sptr outputWS = getProperty("OutputWorkspace");
36 if (outputWS != inputWS)
37 outputWS = inputWS->clone();
38
40
41 Workspace_sptr instWS = this->getProperty("InstrumentWorkspace");
42 if (instWS) {
43 ExperimentInfo_sptr ei = std::dynamic_pointer_cast<ExperimentInfo>(instWS);
44 if (!ei)
45 throw std::invalid_argument("Wrong type of workspace");
46 instrument = ei->getInstrument();
47 outputWS->setInstrument(instrument);
48 } else {
49 instrument = outputWS->getInstrument();
50 }
51
52 Units::Energy energyUnit;
53 for (int i = 0; i < outputWS->getNumberPeaks(); ++i) {
54 Peak &peak = outputWS->getPeak(i);
55
56 const auto tof = peak.getTOF();
57
58 peak.setInstrument(instrument);
59 peak.setDetectorID(peak.getDetectorID());
60
61 energyUnit.initialize(peak.getL1(), 0, {{UnitParams::l2, peak.getL2()}});
62 const double energy = energyUnit.singleFromTOF(tof);
63 peak.setInitialEnergy(energy);
64 peak.setFinalEnergy(energy);
65 }
66
67 setProperty("OutputWorkspace", outputWS);
68}
69} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
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.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
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:714
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:212
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:379
int getDetectorID() const
Get the ID of the detector at the center of the peak
Definition: Peak.cpp:271
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
Definition: Peak.cpp:300
void initialize(const double &_l1, const int &_emode, const UnitParametersMap &params)
Initialize the unit to perform conversion using singleToTof() and singleFromTof()
Definition: Unit.cpp:132
Energy in milli-electronvolts.
Definition: Unit.h:331
double singleFromTOF(const double tof) const override
Convert a single tof value to this unit.
Definition: Unit.cpp:475
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
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:53
@ Output
An output workspace.
Definition: Property.h:54