Mantid
Loading...
Searching...
No Matches
Instrument.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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#pragma once
8
9#include "MantidGeometry/DllConfig.h"
15
17
18#include <map>
19#include <queue>
20#include <string>
21#include <tuple>
22#include <unordered_map>
23#include <vector>
24
25namespace Mantid {
27using detid2det_map = std::map<detid_t, Geometry::IDetector_const_sptr>;
28
29namespace Geometry {
30class ComponentInfo;
31class DetectorInfo;
33class ParameterMap;
34class ReferenceFrame;
37 std::map<std::pair<std::string, const IComponent *>, std::shared_ptr<XMLInstrumentParameter>>;
38
47class MANTID_GEOMETRY_DLL Instrument : public CompAssembly {
48public:
50 std::string type() const override { return "Instrument"; }
51
52 Instrument(const std::shared_ptr<const Instrument> &instr, const std::shared_ptr<ParameterMap> &map);
53 Instrument();
54 Instrument(const std::string &name);
55 Instrument(const Instrument &);
56
57 Instrument *clone() const override;
58
59 bool hasSource() const;
60 bool hasSample() const;
61
62 IComponent_const_sptr getSource() const;
63 IComponent_const_sptr getSample() const;
64 Kernel::V3D getBeamDirection() const;
65
66 IDetector_const_sptr getDetector(const detid_t &detector_id) const;
67 const IDetector *getBaseDetector(const detid_t &detector_id) const;
68 bool isMonitor(const detid_t &detector_id) const;
69 bool isMonitor(const std::set<detid_t> &detector_ids) const;
70
72 IDetector_const_sptr getDetectorG(const std::set<detid_t> &det_ids) const;
73
75 std::vector<IDetector_const_sptr> getDetectors(const std::vector<detid_t> &det_ids) const;
76
78 std::vector<IDetector_const_sptr> getDetectors(const std::set<detid_t> &det_ids) const;
79
84 void markAsSamplePos(const IComponent *);
85
90 void markAsSource(const IComponent *);
91
95 void markAsDetector(const IDetector *);
96 void markAsDetectorIncomplete(const IDetector *);
97 void markAsDetectorFinalize();
98
103 void markAsMonitor(const IDetector *);
104
106 void removeDetector(IDetector *);
107
109 void getDetectors(detid2det_map &out_map) const;
110
111 std::vector<detid_t> getDetectorIDs(bool skipMonitors = false) const;
112
113 std::size_t getNumberDetectors(bool skipMonitors = false) const;
114
115 void getMinMaxDetectorIDs(detid_t &min, detid_t &max) const;
116
117 void getDetectorsInBank(std::vector<IDetector_const_sptr> &dets, const IComponent &comp) const;
118 void getDetectorsInBank(std::vector<IDetector_const_sptr> &dets, const std::string &bankName) const;
119
121 std::vector<detid_t> getMonitors() const;
122
124 void getBoundingBox(BoundingBox &assemblyBox) const override;
125
127 std::shared_ptr<const std::vector<IObjComponent_const_sptr>> getPlottable() const;
128
130 std::shared_ptr<const IComponent> getComponentByID(const IComponent *id) const;
131
133 std::vector<std::shared_ptr<const IComponent>> getAllComponentsWithName(const std::string &cname) const;
134
137 InstrumentParameterCache &getLogfileCache() { return m_logfileCache; }
138 const InstrumentParameterCache &getLogfileCache() const { return m_logfileCache; }
139
142 std::map<std::string, std::string> &getLogfileUnit() { return m_logfileUnit; }
143
147 std::string getDefaultView() const { return m_defaultView; }
151 void setDefaultView(const std::string &type);
154 std::string getDefaultAxis() const { return m_defaultViewAxis; }
157 void setDefaultViewAxis(const std::string &axis) { m_defaultViewAxis = axis; }
158 // Allow access by index
159 using CompAssembly::getChild;
160
162 std::shared_ptr<const Instrument> baseInstrument() const;
163
166 std::shared_ptr<ParameterMap> getParameterMap() const;
167
169 Types::Core::DateAndTime getValidFromDate() const { return m_ValidFrom; }
170
172 Types::Core::DateAndTime getValidToDate() const { return m_ValidTo; }
173
176 void setValidFromDate(const Types::Core::DateAndTime &val);
177
180 void setValidToDate(const Types::Core::DateAndTime &val) { m_ValidTo = val; }
181
182 // Methods for use with indirect geometry instruments,
183 // where the physical instrument differs from the 'neutronic' one
184 std::shared_ptr<const Instrument> getPhysicalInstrument() const;
185 void setPhysicalInstrument(std::unique_ptr<Instrument>);
186
187 void getInstrumentParameters(double &l1, Kernel::V3D &beamline, double &beamline_norm, Kernel::V3D &samplePos) const;
188
189 void saveNexus(::NeXus::File *file, const std::string &group) const;
190 void loadNexus(::NeXus::File *file, const std::string &group);
191
192 void setFilename(const std::string &filename);
193 const std::string &getFilename() const;
194 void setXmlText(const std::string &XmlText);
195 const std::string &getXmlText() const;
196
198 void setReferenceFrame(std::shared_ptr<ReferenceFrame> frame);
200 std::shared_ptr<const ReferenceFrame> getReferenceFrame() const;
201
203 enum ContainsState { Full, Partial, None };
204
207 ContainsState containsRectDetectors() const;
208
209 std::vector<RectangularDetector_const_sptr> findRectDetectors() const;
210
211 bool isMonitorViaIndex(const size_t index) const;
212 size_t detectorIndex(const detid_t detID) const;
213 std::shared_ptr<ParameterMap> makeLegacyParameterMap() const;
214
215 bool isEmptyInstrument() const;
216
218 virtual int add(IComponent *component) override;
219
220 void parseTreeAndCacheBeamline();
221 std::pair<std::unique_ptr<ComponentInfo>, std::unique_ptr<DetectorInfo>>
222 makeBeamline(ParameterMap &pmap, const ParameterMap *source = nullptr) const;
223
224private:
226 void saveDetectorSetInfoToNexus(::NeXus::File *file, const std::vector<detid_t> &detIDs) const;
227
228 bool validateComponentProperties(IComponent_const_sptr component) const;
229
230 void addInstrumentChildrenToQueue(std::queue<IComponent_const_sptr> &queue) const;
231 bool addAssemblyChildrenToQueue(std::queue<IComponent_const_sptr> &queue, IComponent_const_sptr component) const;
232
235
237 void appendPlottable(const CompAssembly &ca, std::vector<IObjComponent_const_sptr> &lst) const;
238
239 std::pair<std::unique_ptr<ComponentInfo>, std::unique_ptr<DetectorInfo>>
240 makeWrappers(ParameterMap &pmap, const ComponentInfo &componentInfo, const DetectorInfo &detectorInfo) const;
241
244 std::vector<std::tuple<detid_t, IDetector_const_sptr, bool>> m_detectorCache;
245
249
253
258
268 std::map<std::string, std::string> m_logfileUnit;
269
272 std::string m_defaultView;
275 std::string m_defaultViewAxis;
276
278 std::shared_ptr<const Instrument> m_instr;
279
281 std::shared_ptr<ParameterMap> m_map_nonconst;
282
284 Types::Core::DateAndTime m_ValidFrom;
286 Types::Core::DateAndTime m_ValidTo;
287
289 mutable std::string m_filename;
290
292 mutable std::string m_xmlText;
293
296 std::shared_ptr<const Instrument> m_physicalInstrument;
297
299 std::shared_ptr<ReferenceFrame> m_referenceFrame;
300
302 std::shared_ptr<const DetectorInfo> m_detectorInfo{nullptr};
303
305 std::shared_ptr<const ComponentInfo> m_componentInfo{nullptr};
306
308 bool m_isPhysicalInstrument{false};
309};
310namespace Conversion {
311
312MANTID_GEOMETRY_DLL double tofToDSpacingFactor(const double l1, const double l2, const double twoTheta,
313 const double offset);
314
315double MANTID_GEOMETRY_DLL tofToDSpacingFactor(const double l1, const double l2, const double twoTheta,
316 const std::vector<detid_t> &detectors,
317 const std::map<detid_t, double> &offsets);
318} // namespace Conversion
319
320} // namespace Geometry
321} // Namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
IntArray detectorIndex
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition: BoundingBox.h:34
Class for Assembly of geometric components.
Definition: CompAssembly.h:31
ComponentInfo : Provides a component centric view on to the instrument.
Definition: ComponentInfo.h:40
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
Definition: DetectorInfo.h:49
base class for Geometric IComponent
Definition: IComponent.h:51
Interface class for detector objects.
Definition: IDetector.h:43
Base Instrument Class.
Definition: Instrument.h:47
std::string m_filename
Path to the original IDF .xml file that was loaded for this instrument.
Definition: Instrument.h:289
const InstrumentParameterCache & getLogfileCache() const
Definition: Instrument.h:138
std::string m_defaultViewAxis
Stores from which side the instrument will be viewed from, initially in the instrument viewer,...
Definition: Instrument.h:275
std::string m_xmlText
Contents of the IDF .xml file that was loaded for this instrument.
Definition: Instrument.h:292
const IComponent * m_sampleCache
Purpose to hold copy of samplePos component.
Definition: Instrument.h:252
std::string getDefaultAxis() const
Retrieves from which side the instrument to be viewed from when the instrument viewer first starts,...
Definition: Instrument.h:154
ContainsState
To determine whether the instrument contains elements of some type.
Definition: Instrument.h:203
std::shared_ptr< const Instrument > m_instr
Pointer to the "real" instrument, for parametrized Instrument.
Definition: Instrument.h:278
std::string m_defaultView
Stores the default type of the instrument view: 3D or one of the "unwrapped".
Definition: Instrument.h:272
std::string getDefaultView() const
Get the default type of the instrument view.
Definition: Instrument.h:147
std::map< std::string, std::string > m_logfileUnit
Store units used by users to specify angles in IDFs and associated parameter files.
Definition: Instrument.h:268
std::vector< std::tuple< detid_t, IDetector_const_sptr, bool > > m_detectorCache
Map which holds detector-IDs and pointers to detector components, and monitor flags.
Definition: Instrument.h:244
Instrument & operator=(const Instrument &)
Private copy assignment operator.
std::map< std::string, std::string > & getLogfileUnit()
Get information about the units used for parameters described in the IDF and associated parameter fil...
Definition: Instrument.h:142
Types::Core::DateAndTime m_ValidTo
the date at which the instrument definition is no longer valid.
Definition: Instrument.h:286
const IComponent * m_sourceCache
Purpose to hold copy of source component.
Definition: Instrument.h:248
std::string type() const override
String description of the type of component.
Definition: Instrument.h:50
Types::Core::DateAndTime getValidFromDate() const
Definition: Instrument.h:169
std::shared_ptr< const Instrument > m_physicalInstrument
Pointer to the physical instrument, where this differs from the 'neutronic' one (indirect geometry)
Definition: Instrument.h:296
std::shared_ptr< ParameterMap > m_map_nonconst
Non-const pointer to the parameter map.
Definition: Instrument.h:281
InstrumentParameterCache m_logfileCache
To store info about the parameters defined in IDF.
Definition: Instrument.h:257
void setValidToDate(const Types::Core::DateAndTime &val)
Set the date at which the instrument definition is no longer valid.
Definition: Instrument.h:180
void setDefaultViewAxis(const std::string &axis)
Retrieves from which side the instrument to be viewed from when the instrument viewer first starts,...
Definition: Instrument.h:157
std::shared_ptr< ReferenceFrame > m_referenceFrame
Pointer to the reference frame object.
Definition: Instrument.h:299
InstrumentParameterCache & getLogfileCache()
Get information about the parameters described in the instrument definition file and associated param...
Definition: Instrument.h:137
Types::Core::DateAndTime m_ValidFrom
the date from which the instrument definition begins to be valid.
Definition: Instrument.h:284
Types::Core::DateAndTime getValidToDate() const
Definition: Instrument.h:172
ReferenceFrame : Holds reference frame information from the geometry description file.
This class is used to store information about parameters in XML instrument definition files and instr...
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL double tofToDSpacingFactor(const double l1, const double l2, const double twoTheta, const double offset)
Calculate and return conversion factor from tof to d-spacing.
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
Definition: IComponent.h:161
std::map< std::pair< std::string, const IComponent * >, std::shared_ptr< XMLInstrumentParameter > > InstrumentParameterCache
Convenience typedef.
Definition: Instrument.h:37
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
Definition: IDetector.h:102
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.
Definition: SpectrumInfo.h:21
std::map< detid_t, Geometry::IDetector_const_sptr > detid2det_map
Typedef of a map from detector ID to detector shared pointer.
Definition: Instrument.h:27
Generate a tableworkspace to store the calibration results.