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:
125 const std::string name() const override { return "FindDetectorsPar"; };
127 const std::string summary() const override {
128 return "The algorithm returns the angular parameters and second flight "
129 "path for a workspace detectors (data, usually availble in par or "
130 "phx file)";
131 }
132
134 int version() const override { return 1; };
136 const std::string category() const override { return "DataHandling\\Instrument"; }
139 std::vector<double> const &getAzimuthal() const { return azimuthal; }
140 std::vector<double> const &getPolar() const { return polar; }
141 std::vector<double> const &getAzimWidth() const { return azimuthalWidth; }
142 std::vector<double> const &getPolarWidth() const { return polarWidth; }
143 std::vector<double> const &getFlightPath() const { return secondaryFlightpath; }
144 std::vector<size_t> const &getDetID() const { return detID; }
146 size_t getNDetectors() const { return m_nDetectors; }
147
148private:
149 // Implement abstract Algorithm methods
150 void init() override;
151 void exec() override;
155 bool m_SizesAreLinear = false;
156
157 // numner of real(valid and non-monitor) detectors calculated by the alvorithm
158 size_t m_nDetectors = 0;
159 // the vectors which represent detector's parameters as linear structure
160 std::vector<double> azimuthal;
161 std::vector<double> polar;
162 std::vector<double> azimuthalWidth;
163 std::vector<double> polarWidth;
164 std::vector<double> secondaryFlightpath;
165 std::vector<size_t> detID;
166
167 // calculate generic detectors parameters:
168 void calcDetPar(const Geometry::IDetector &detector, const Kernel::V3D &observer, DetParameters &detParameters);
169
175 void setOutputTable();
177 void extractAndLinearize(const std::vector<DetParameters> &detPar);
179 void populate_values_from_file(const API::MatrixWorkspace_sptr &inputWS);
181 size_t loadParFile(const std::string &fileName);
182
183protected: // for testing purposes
186 int count_changes(const char *const Buf, size_t buf_size);
190 size_t get_my_line(std::ifstream &in, char *buf, size_t buf_size, const char DELIM);
193 FileTypeDescriptor get_ASCII_header(std::string const &fileName, std::ifstream &data_stream);
195 void load_plain(std::ifstream &stream, std::vector<double> &Data, FileTypeDescriptor const &FILE_TYPE);
196};
197
201public:
214 int64_t detID;
215 // default detector ID -- -1 means undefined
218};
219
228 // if azimuthal and polar sizes expressed in angular or linear units
233
234public:
237 m_AzimMin(FLT_MAX), m_PolarMin(FLT_MAX), m_AzimMax(-FLT_MAX), m_PolarMax(-FLT_MAX), m_nComponents(0) {}
238 void addDetInfo(const Geometry::IDetector &det, const Kernel::V3D &Observer);
239 void returnAvrgDetPar(DetParameters &avrgDet);
240
241 void setUseSpherical(bool shouldWe = true) { m_useSphericalSizes = shouldWe; }
242
243 static double nearAngle(const double &baseAngle, const double &anAngle);
244};
245
246} // end namespace DataHandling
247} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
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.