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
16#include "MantidTypes/Core/DateAndTime.h"
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;
38 std::map<std::pair<std::string, const IComponent *>, std::shared_ptr<XMLInstrumentParameter>>;
39
48class MANTID_GEOMETRY_DLL Instrument : public CompAssembly {
49public:
51 std::string type() const override { return "Instrument"; }
52
53 Instrument(const std::shared_ptr<const Instrument> &instr, const std::shared_ptr<ParameterMap> &map);
54 Instrument();
55 Instrument(const std::string &name);
56 Instrument(const Instrument &);
57
58 Instrument *clone() const override;
59
60 bool hasSource() const;
61 bool hasSample() const;
62
63 IComponent_const_sptr getSource() const;
64 IComponent_const_sptr getSample() const;
65 Kernel::V3D getBeamDirection() const;
66
67 IDetector_const_sptr getDetector(const detid_t &detector_id) const;
68 const IDetector *getBaseDetector(const detid_t &detector_id) const;
69 bool isMonitor(const detid_t &detector_id) const;
70 bool isMonitor(const std::set<detid_t> &detector_ids) const;
71
73 IDetector_const_sptr getDetectorG(const std::set<detid_t> &det_ids) const;
74
76 std::vector<IDetector_const_sptr> getDetectors(const std::vector<detid_t> &det_ids) const;
77
79 std::vector<IDetector_const_sptr> getDetectors(const std::set<detid_t> &det_ids) const;
80
85 void markAsSamplePos(const IComponent *);
86
91 void markAsSource(const IComponent *);
92
96 void markAsDetector(const IDetector *);
97 void markAsDetectorIncomplete(const IDetector *);
98 void markAsDetectorFinalize();
99
104 void markAsMonitor(const IDetector *);
105
107 void removeDetector(IDetector *);
108
110 void getDetectors(detid2det_map &out_map) const;
111
112 std::vector<detid_t> getDetectorIDs(bool skipMonitors = false) const;
113
114 std::size_t getNumberDetectors(bool skipMonitors = false) const;
115
116 void getMinMaxDetectorIDs(detid_t &min, detid_t &max) const;
117
118 void getDetectorsInBank(std::vector<IDetector_const_sptr> &dets, const IComponent &comp) const;
119 void getDetectorsInBank(std::vector<IDetector_const_sptr> &dets, const std::string &bankName) const;
120 std::set<detid_t> getDetectorIDsInBank(const std::string &bankName) const;
121
123 std::vector<detid_t> getMonitors() const;
124
126 void getBoundingBox(BoundingBox &assemblyBox) const override;
127
129 std::shared_ptr<const std::vector<IObjComponent_const_sptr>> getPlottable() const;
130
132 std::shared_ptr<const IComponent> getComponentByID(const IComponent *id) const;
133
135 std::vector<std::shared_ptr<const IComponent>> getAllComponentsWithName(const std::string &cname) const;
136
139 InstrumentParameterCache &getLogfileCache() { return m_logfileCache; }
140 const InstrumentParameterCache &getLogfileCache() const { return m_logfileCache; }
141
144 std::map<std::string, std::string> &getLogfileUnit() { return m_logfileUnit; }
145
149 const std::string &getDefaultView() const { return m_defaultView; }
153 void setDefaultView(const std::string &type);
156 const std::string &getDefaultAxis() const { return m_defaultViewAxis; }
159 void setDefaultViewAxis(const std::string &axis) { m_defaultViewAxis = axis; }
160 // Allow access by index
161 using CompAssembly::getChild;
162
164 std::shared_ptr<const Instrument> baseInstrument() const;
165
168 std::shared_ptr<ParameterMap> getParameterMap() const;
169
171 Types::Core::DateAndTime getValidFromDate() const { return m_ValidFrom; }
172
174 Types::Core::DateAndTime getValidToDate() const { return m_ValidTo; }
175
177 void setValidFromDate(const Types::Core::DateAndTime &val);
178
181 void setValidToDate(const Types::Core::DateAndTime &val) { m_ValidTo = val; }
182
183 // Methods for use with indirect geometry instruments,
184 // where the physical instrument differs from the 'neutronic' one
185 std::shared_ptr<const Instrument> getPhysicalInstrument() const;
186 void setPhysicalInstrument(std::unique_ptr<Instrument>);
187
188 void getInstrumentParameters(double &l1, Kernel::V3D &beamline, double &beamline_norm, Kernel::V3D &samplePos) const;
189
190 void saveNexus(Nexus::File *file, const std::string &group) const;
191 void loadNexus(Nexus::File *file, const std::string &group);
192
193 void setFilename(const std::string &filename);
194 const std::string &getFilename() const;
195 void setXmlText(const std::string &XmlText);
196 const std::string &getXmlText() const;
197
199 void setReferenceFrame(std::shared_ptr<ReferenceFrame> frame);
201 std::shared_ptr<const ReferenceFrame> getReferenceFrame() const;
202
204 enum ContainsState { Full, Partial, None };
205
208 ContainsState containsRectDetectors() const;
209
210 std::vector<RectangularDetector_const_sptr> findRectDetectors() const {
211 return findDetectorsOfType<RectangularDetector>();
212 }
213 std::vector<GridDetector_const_sptr> findGridDetectors() const { return findDetectorsOfType<GridDetector>(); }
214
215 bool isMonitorViaIndex(const size_t index) const;
216 size_t detectorIndex(const detid_t detID) const;
217 std::shared_ptr<ParameterMap> makeLegacyParameterMap() const;
218
219 bool isEmptyInstrument() const;
220
221 void parseTreeAndCacheBeamline();
222 std::pair<std::unique_ptr<ComponentInfo>, std::unique_ptr<DetectorInfo>>
223 makeBeamline(ParameterMap &pmap, const ParameterMap *source = nullptr) const;
224
226
227private:
229 void saveDetectorSetInfoToNexus(Nexus::File *file, const std::vector<detid_t> &detIDs) const;
230
231 bool validateComponentProperties(IComponent_const_sptr component) const;
232
233 void addInstrumentChildrenToQueue(std::queue<IComponent_const_sptr> &queue) const;
234 bool addAssemblyChildrenToQueue(std::queue<IComponent_const_sptr> &queue, IComponent_const_sptr component) const;
235 template <typename T> std::vector<std::shared_ptr<const T>> findDetectorsOfType() const {
236 std::queue<IComponent_const_sptr> compQueue; // Search queue
237 addInstrumentChildrenToQueue(compQueue);
238
239 std::vector<std::shared_ptr<const T>> detectors;
240
242
243 while (!compQueue.empty()) {
244 comp = compQueue.front();
245 compQueue.pop();
246
247 if (!validateComponentProperties(comp))
248 continue;
249
250 if (auto const detector = std::dynamic_pointer_cast<const T>(comp)) {
251 detectors.push_back(detector);
252 } else {
253 // If component is a ComponentAssembly, we add its children to the queue to check if they're type T
254 addAssemblyChildrenToQueue(compQueue, comp);
255 }
256 }
257 return detectors;
258 }
259
262
264 void appendPlottable(const CompAssembly &ca, std::vector<IObjComponent_const_sptr> &lst) const;
265
266 std::pair<std::unique_ptr<ComponentInfo>, std::unique_ptr<DetectorInfo>>
267 makeWrappers(ParameterMap &pmap, const ComponentInfo &componentInfo, const DetectorInfo &detectorInfo) const;
268
271 std::vector<std::tuple<detid_t, IDetector_const_sptr, bool>> m_detectorCache;
272
275 const IComponent *m_sourceCache = nullptr;
276
279 const IComponent *m_sampleCache = nullptr;
280
285
295 std::map<std::string, std::string> m_logfileUnit;
296
299 std::string m_defaultView;
302 std::string m_defaultViewAxis;
303
305 std::shared_ptr<const Instrument> m_instr;
306
308 std::shared_ptr<ParameterMap> m_map_nonconst;
309
311 Types::Core::DateAndTime m_ValidFrom;
313 Types::Core::DateAndTime m_ValidTo;
314
316 mutable std::string m_filename;
317
319 mutable std::string m_xmlText;
320
323 std::shared_ptr<const Instrument> m_physicalInstrument;
324
326 std::shared_ptr<ReferenceFrame> m_referenceFrame;
327
329 std::shared_ptr<const DetectorInfo> m_detectorInfo{nullptr};
330
332 std::shared_ptr<const ComponentInfo> m_componentInfo{nullptr};
333
335 bool m_isPhysicalInstrument{false};
336};
337namespace Conversion {
338
339MANTID_GEOMETRY_DLL double tofToDSpacingFactor(const double l1, const double l2, const double twoTheta,
340 const double offset);
341
342double MANTID_GEOMETRY_DLL tofToDSpacingFactor(const double l1, const double l2, const double twoTheta,
343 const std::vector<detid_t> &detectors,
344 const std::map<detid_t, double> &offsets);
345
346MANTID_GEOMETRY_DLL double calculateDIFCCorrection(const double l1, const double l2, const double twoTheta,
347 const double offset, const double binWidth);
348} // namespace Conversion
349
350} // namespace Geometry
351} // Namespace Mantid
std::string name
Definition Run.cpp:60
std::map< DeltaEMode::Type, std::string > index
IntArray detectorIndex
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition BoundingBox.h:33
Class for Assembly of geometric components.
ComponentInfo : Provides a component centric view on to the instrument.
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
base class for Geometric IComponent
Definition IComponent.h:53
Interface class for detector objects.
Definition IDetector.h:43
InstrumentVisitor : Visitor for components with access to Info wrapping features.
Base Instrument Class.
Definition Instrument.h:48
std::string m_filename
Path to the original IDF .xml file that was loaded for this instrument.
Definition Instrument.h:316
const InstrumentParameterCache & getLogfileCache() const
Definition Instrument.h:140
std::string m_defaultViewAxis
Stores from which side the instrument will be viewed from, initially in the instrument viewer,...
Definition Instrument.h:302
std::string m_xmlText
Contents of the IDF .xml file that was loaded for this instrument.
Definition Instrument.h:319
std::vector< GridDetector_const_sptr > findGridDetectors() const
Definition Instrument.h:213
ContainsState
To determine whether the instrument contains elements of some type.
Definition Instrument.h:204
std::shared_ptr< const Instrument > m_instr
Pointer to the "real" instrument, for parametrized Instrument.
Definition Instrument.h:305
std::string m_defaultView
Stores the default type of the instrument view: 3D or one of the "unwrapped".
Definition Instrument.h:299
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:295
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:271
Instrument & operator=(const Instrument &)
Private copy assignment operator.
std::vector< RectangularDetector_const_sptr > findRectDetectors() const
Definition Instrument.h:210
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:144
Types::Core::DateAndTime m_ValidTo
the date at which the instrument definition is no longer valid.
Definition Instrument.h:313
const std::string & getDefaultView() const
Get the default type of the instrument view.
Definition Instrument.h:149
const std::string & getDefaultAxis() const
Retrieves from which side the instrument to be viewed from when the instrument viewer first starts,...
Definition Instrument.h:156
std::string type() const override
String description of the type of component.
Definition Instrument.h:51
Types::Core::DateAndTime getValidFromDate() const
Definition Instrument.h:171
std::shared_ptr< const Instrument > m_physicalInstrument
Pointer to the physical instrument, where this differs from the 'neutronic' one (indirect geometry)
Definition Instrument.h:323
std::shared_ptr< ParameterMap > m_map_nonconst
Non-const pointer to the parameter map.
Definition Instrument.h:308
InstrumentParameterCache m_logfileCache
To store info about the parameters defined in IDF.
Definition Instrument.h:284
void setValidToDate(const Types::Core::DateAndTime &val)
Set the date at which the instrument definition is no longer valid.
Definition Instrument.h:181
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:159
std::vector< std::shared_ptr< const T > > findDetectorsOfType() const
Definition Instrument.h:235
std::shared_ptr< ReferenceFrame > m_referenceFrame
Pointer to the reference frame object.
Definition Instrument.h:326
InstrumentParameterCache & getLogfileCache()
Get information about the parameters described in the instrument definition file and associated param...
Definition Instrument.h:139
Types::Core::DateAndTime m_ValidFrom
the date from which the instrument definition begins to be valid.
Definition Instrument.h:311
Types::Core::DateAndTime getValidToDate() const
Definition Instrument.h:174
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 calculateDIFCCorrection(const double l1, const double l2, const double twoTheta, const double offset, const double binWidth)
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:167
std::map< std::pair< std::string, const IComponent * >, std::shared_ptr< XMLInstrumentParameter > > InstrumentParameterCache
Convenience typedef.
Definition Instrument.h:38
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.
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.