Mantid
Loading...
Searching...
No Matches
FindDetectorsPar.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2009 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 <float.h>
10#include <fstream>
11
12#include "MantidAPI/Algorithm.h"
13#include "MantidDataHandling/DllConfig.h"
15
16namespace Mantid {
17namespace DataHandling {
50 PAR_type, //< ASCII PAR file
51 PHX_type, //< ASCII phx file
52 SPE_type, //< spe file, this loader would not work with spe file, left for
53 // compartibility with old algorithms.
54 BIN_file, //< binary file is not an ASCII file, so ascii loader would not work
55 // on it
57};
58
65 std::streampos data_start_position; //< the position in the file where the
66 // data structure starts
67 size_t nData_records, //< number of data records -- actually nDetectors
68 nData_blocks; //< nEnergy bins for SPE file, 5 or 6 for PAR file and 7 for
69 // PHX file
70 char line_end; //< the character which ends line in current ASCII file 0x0A
71 //(LF)
72 // Unix, 0x0D (CR) Mac and 0x0D 0x0A (CR LF) Win, but the last is interpreted
73 // as 0x0A here
75};
76
119// predefine class, used to cashe precalculated detector's parameters
120class DetParameters;
121
122class MANTID_DATAHANDLING_DLL FindDetectorsPar : public API::Algorithm {
123public:
124 virtual ~FindDetectorsPar() = default;
126 const std::string name() const override { return "FindDetectorsPar"; };
128 const std::string summary() const override {
129 return "The algorithm returns the angular parameters and second flight "
130 "path for a workspace detectors (data, usually availble in par or "
131 "phx file)";
132 }
133
135 int version() const override { return 1; };
137 const std::string category() const override { return "DataHandling\\Instrument"; }
140 std::vector<double> const &getAzimuthal() const { return azimuthal; }
141 std::vector<double> const &getPolar() const { return polar; }
142 std::vector<double> const &getAzimWidth() const { return azimuthalWidth; }
143 std::vector<double> const &getPolarWidth() const { return polarWidth; }
144 std::vector<double> const &getFlightPath() const { return secondaryFlightpath; }
145 std::vector<size_t> const &getDetID() const { return detID; }
147 size_t getNDetectors() const { return m_nDetectors; }
148
149private:
150 // Implement abstract Algorithm methods
151 void init() override;
152 void exec() override;
156 bool m_SizesAreLinear = false;
157
158 // numner of real(valid and non-monitor) detectors calculated by the alvorithm
159 size_t m_nDetectors = 0;
160 // the vectors which represent detector's parameters as linear structure
161 std::vector<double> azimuthal;
162 std::vector<double> polar;
163 std::vector<double> azimuthalWidth;
164 std::vector<double> polarWidth;
165 std::vector<double> secondaryFlightpath;
166 std::vector<size_t> detID;
167
168 // calculate generic detectors parameters:
169 void calcDetPar(const Geometry::IDetector &detector, const Kernel::V3D &observer, DetParameters &detParameters);
170
176 void setOutputTable();
178 void extractAndLinearize(const std::vector<DetParameters> &detPar);
180 void populate_values_from_file(const API::MatrixWorkspace_sptr &inputWS);
182 size_t loadParFile(const std::string &fileName);
183
184protected: // for testing purposes
187 int count_changes(const char *const Buf, size_t buf_size);
191 size_t get_my_line(std::ifstream &in, char *buf, size_t buf_size, const char DELIM);
194 FileTypeDescriptor get_ASCII_header(std::string const &fileName, std::ifstream &data_stream);
196 void load_plain(std::ifstream &stream, std::vector<double> &Data, FileTypeDescriptor const &FILE_TYPE);
197};
198
202public:
215 int64_t detID;
216 // default detector ID -- -1 means undefined
218 : azimutAngle(0.), polarAngle(0.), secondaryFlightPath(0.), azimWidth(0.), polarWidth(0.), detID(-1) {}
219};
220
229 // if azimuthal and polar sizes expressed in angular or linear units
234
235public:
238 m_AzimMin(FLT_MAX), m_PolarMin(FLT_MAX), m_AzimMax(-FLT_MAX), m_PolarMax(-FLT_MAX), m_nComponents(0) {}
239 void addDetInfo(const Geometry::IDetector &det, const Kernel::V3D &Observer);
240 void returnAvrgDetPar(DetParameters &avrgDet);
241
242 void setUseSpherical(bool shouldWe = true) { m_useSphericalSizes = shouldWe; }
243
244 static double nearAngle(const double &baseAngle, const double &anAngle);
245};
246
247} // end namespace DataHandling
248} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
helper class-collection to keep together the parameters, which characterize average composite detecto...
void addDetInfo(const Geometry::IDetector &det, const Kernel::V3D &Observer)
method to cacluate the detectors parameters and add them to the detectors averages
static double nearAngle(const double &baseAngle, const double &anAngle)
method calculates an angle closest to the initial one taken on a ring e.g.
size_t m_nComponents
numbr of primary detectors, contributing into this detector
void returnAvrgDetPar(DetParameters &avrgDet)
Method processes accumulated averages and return them in preexistent avrgDet class.
void setUseSpherical(bool shouldWe=true)
Small helper class-holder used to precalculate the detectors parameters in spherical coordinate syste...
double azimWidth
linear or angular size of the bounding box encapsulating detector and alighned tangentially to the co...
double azimutAngle
azimuthal detector's angle in spherical coordinate system alighned with the beam
double secondaryFlightPath
scattering source – detector' distance
double polarAngle
polar detector's angle in spherical coordinate system alighned with the beam
size_t getNDetectors() const
number of real detectors, calculated by algorithm
int version() const override
Algorithm's version for identification overriding a virtual method.
std::vector< double > const & getPolarWidth() const
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
std::vector< size_t > const & getDetID() const
std::vector< double > const & getAzimWidth() const
const std::string summary() const override
Summary of algorithms purpose.
std::vector< double > const & getAzimuthal() const
the accessors, used to return algorithm results when called as Child Algorithm, without setting the p...
std::vector< double > const & getPolar() const
std::vector< double > const & getFlightPath() const
FileTypeDescriptor current_ASCII_file
if ASCII file is selected as the datasource, this structure describes the type of this file.
Interface class for detector objects.
Definition: IDetector.h:43
Class for 3D vectors.
Definition: V3D.h:34
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
fileTypes
file types currently supported by ASCII loader are: 1) an ASCII Tobyfit par file Syntax: >> par = get...
Helper class which provides the Collimation Length for SANS instruments.
Description of the ASCII data header, common for all ASCII PAR and PHX files.