30 auto ws_valid = std::make_shared<Kernel::CompositeValidator>();
38 "Name of an input Matrix Workspace with instrument.");
41 "Name of the output Table workspace with pre-processed "
42 "detectors data. If the workspace exists, it will be "
46 "Returns masked state of the detectors. If this option is "
47 "false, the masked detectors are just dropped from the "
48 "resulting workspace and spectra-to detectors map has to be "
49 "used to analyse the spectra. This is temporary parameter "
50 "and logic necessary until Mantid masks signal by 0 rather "
54 "If target workspace already exists as the result of "
55 "previous deployment of this algorithm, the algorithm just "
56 "updated masks states column instead of calculating the "
57 "whole target workspace. The target workspace has to be "
58 "appropriate for the source workspace This is temporary "
59 "parameter and logic necessary until Mantid masks signal by "
60 "0 rather then NaN.");
63 "This option makes sense for Indirect instrument, where each "
64 "detector can have its own energy, defined by correspondent "
65 "crystal-analyzer position.\n"
66 "If this option is selected for other instrument types, the "
67 "value of eFixed is taken from workspace property "
74 "is missing and is set to NaN if no such properties are "
75 "defined on the input workspace.");
94 bool updateMasks(
false);
97 if (API::AnalysisDataService::Instance().doesExist(wsName)) {
99 std::dynamic_pointer_cast<DataObjects::TableWorkspace>(API::AnalysisDataService::Instance().retrieve(wsName));
101 auto *pMasksArray = targWS->getColDataArray<
int>(
"detMask");
105 if (this->
getProperty(
"GetEFixed") && !targWS->getColDataArray<
float>(
"eFixed"))
126std::shared_ptr<DataObjects::TableWorkspace>
128 const size_t nHist = inputWS->getNumberHistograms();
131 auto targWS = std::make_shared<TableWorkspace>(nHist);
133 targWS->addColumn(
"V3D",
"DetDirections");
135 targWS->addColumn(
"double",
"L2");
137 targWS->addColumn(
"double",
"TwoTheta");
138 targWS->addColumn(
"double",
"Azimuthal");
140 targWS->addColumn(
"int",
"DetectorID");
142 targWS->addColumn(
"size_t",
"detIDMap");
144 targWS->addColumn(
"size_t",
"spec2detMap");
149 targWS->addColumn(
"int",
"detMask");
154 targWS->addColumn(
"float",
"eFixed");
155 targWS->addColumn(
"double",
"DIFA");
156 targWS->addColumn(
"double",
"DIFC");
157 targWS->addColumn(
"double",
"TZERO");
163 double Efi =
getEi(inputWS);
164 targWS->logs()->addProperty<
double>(
"Ei", Efi,
true);
175 g_log.
information() <<
"Preprocessing detector locations in a target reciprocal space\n";
182 if ((!source) || (!sample)) {
183 g_log.
error() <<
" Instrument is not fully defined. Can not identify "
184 "source or sample\n";
186 "Instrument not sufficiently defined: failed to get source and/or "
192 double L1 = source->getDistance(*sample);
193 targWS->logs()->addProperty<
double>(
"L1", L1,
true);
194 g_log.
debug() <<
"Source-sample distance: " << L1 <<
'\n';
197 inputWS->getTitle());
200 std::string InstrName = instrument->getName();
201 targWS->logs()->addProperty<std::string>(
"InstrumentName", InstrName,
203 targWS->logs()->addProperty<
bool>(
"FakeDetectors",
false,
true);
206 auto &sp2detMap = targWS->getColVector<
size_t>(
"spec2detMap");
207 auto &detId = targWS->getColVector<int32_t>(
"DetectorID");
208 auto &detIDMap = targWS->getColVector<
size_t>(
"detIDMap");
209 auto &L2 = targWS->getColVector<
double>(
"L2");
210 auto &TwoTheta = targWS->getColVector<
double>(
"TwoTheta");
211 auto &Azimuthal = targWS->getColVector<
double>(
"Azimuthal");
212 auto &detDir = targWS->getColVector<
Kernel::V3D>(
"DetDirections");
213 auto &DIFA = targWS->getColVector<
double>(
"DIFA");
214 auto &DIFC = targWS->getColVector<
double>(
"DIFC");
215 auto &TZERO = targWS->getColVector<
double>(
"TZERO");
218 auto Efi = targWS->getLogs()->getPropertyValueAsType<
double>(
"Ei");
219 float *pEfixedArray(
nullptr);
222 pEfixedArray = targWS->getColDataArray<
float>(
"eFixed");
225 int *pMasksArray(
nullptr);
227 pMasksArray = targWS->getColDataArray<
int>(
"detMask");
231 size_t nHist = targWS->rowCount();
234 uint32_t liveDetectorsCount(0);
235 const auto &spectrumInfo = inputWS->spectrumInfo();
236 for (
size_t i = 0; i < nHist; i++) {
237 sp2detMap[i] = std::numeric_limits<uint64_t>::quiet_NaN();
238 detId[i] = std::numeric_limits<int32_t>::quiet_NaN();
239 detIDMap[i] = std::numeric_limits<uint64_t>::quiet_NaN();
240 L2[i] = std::numeric_limits<double>::quiet_NaN();
241 DIFC[i] = std::numeric_limits<double>::quiet_NaN();
242 TwoTheta[i] = std::numeric_limits<double>::quiet_NaN();
243 Azimuthal[i] = std::numeric_limits<double>::quiet_NaN();
246 if (!spectrumInfo.hasDetectors(i) || spectrumInfo.isMonitor(i))
250 bool maskDetector = spectrumInfo.isMasked(i);
252 *(pMasksArray + liveDetectorsCount) = maskDetector ? 1 : 0;
253 else if (maskDetector)
256 const auto &spDet = spectrumInfo.detector(i);
259 sp2detMap[i] = liveDetectorsCount;
260 detId[liveDetectorsCount] = int32_t(spDet.getID());
261 detIDMap[liveDetectorsCount] = i;
262 L2[liveDetectorsCount] = spectrumInfo.l2(i);
264 double polar = spectrumInfo.twoTheta(i);
265 double azim = spDet.getPhi();
266 TwoTheta[liveDetectorsCount] = polar;
267 Azimuthal[liveDetectorsCount] = azim;
269 std::vector<int> warningDets;
270 auto diffConsts = spectrumInfo.diffractometerConstants(i, warningDets);
276 double sPhi = sin(polar);
277 double ez = cos(polar);
278 double ex = sPhi * cos(azim);
279 double ey = sPhi * sin(azim);
281 detDir[liveDetectorsCount].setX(ex);
282 detDir[liveDetectorsCount].setY(ey);
283 detDir[liveDetectorsCount].setZ(ez);
295 Efi = par->value<
double>();
296 }
catch (std::runtime_error &) {
299 *(pEfixedArray + liveDetectorsCount) =
static_cast<float>(Efi);
302 liveDetectorsCount++;
304 theProgress.
report(i,
"Preprocessing detectors");
306 targWS->logs()->addProperty<uint32_t>(
"ActualDetectorsNum", liveDetectorsCount,
true);
309 g_log.
information() <<
"Finished preprocessing detector locations. Found: " << liveDetectorsCount
310 <<
" detectors out of: " << nHist <<
" histograms\n";
318 auto *pMasksArray = targWS->getColDataArray<
int>(
"detMask");
320 throw std::invalid_argument(
"target workspace " + targWS->getName() +
321 " does not have defined masks column to update");
323 size_t nHist = targWS->rowCount();
324 const size_t nRows = inputWS->getNumberHistograms();
326 throw std::invalid_argument(
" source workspace " + inputWS->getName() +
" and target workspace " +
327 targWS->getName() +
" are inconsistent as have different numner of detectors");
329 uint32_t liveDetectorsCount(0);
330 const auto &spectrumInfo = inputWS->spectrumInfo();
331 for (
size_t i = 0; i < nHist; i++) {
332 if (!spectrumInfo.hasDetectors(i) || spectrumInfo.isMonitor(i))
336 bool maskDetector = spectrumInfo.isMasked(i);
337 *(pMasksArray + liveDetectorsCount) = maskDetector ? 1 : 0;
339 liveDetectorsCount++;
349 targWS->logs()->addProperty<
double>(
"L1", 1.,
true);
351 targWS->logs()->addProperty<std::string>(
"InstrumentName",
"FakeInstrument",
true);
352 targWS->logs()->addProperty<
bool>(
"FakeDetectors",
true,
true);
355 auto &sp2detMap = targWS->getColVector<
size_t>(
"spec2detMap");
356 auto &detId = targWS->getColVector<int32_t>(
"DetectorID");
357 auto &detIDMap = targWS->getColVector<
size_t>(
"detIDMap");
358 auto &L2 = targWS->getColVector<
double>(
"L2");
359 auto &TwoTheta = targWS->getColVector<
double>(
"TwoTheta");
360 auto &Azimuthal = targWS->getColVector<
double>(
"Azimuthal");
361 auto &detDir = targWS->getColVector<
Kernel::V3D>(
"DetDirections");
365 size_t nHist = targWS->rowCount();
366 targWS->logs()->addProperty<uint32_t>(
"ActualDetectorsNum", uint32_t(nHist),
true);
370 for (
size_t i = 0; i < nHist; i++) {
372 detId[i] =
static_cast<detid_t>(i);
394 auto const *pYAxis =
dynamic_cast<API::NumericAxis const *
>(inWS2D->getAxis(1));
396 return pYAxis !=
nullptr;
412 double Efi = std::numeric_limits<double>::quiet_NaN();
418 Efi = inputWS->run().getPropertyValueAsType<
double>(
"Ei");
424 bool eFixedFound(
false);
427 Efi = inputWS->run().getPropertyValueAsType<
double>(
"eFixed");
433 if (!(EiFound || eFixedFound))
434 g_log.
debug() <<
" Ei/eFixed requested but have not been found\n";
#define DECLARE_ALGORITHM(classname)
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Kernel::Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A validator which checks that a workspace has a valid instrument.
Class to represent a numeric axis of a workspace.
Helper class for reporting progress from algorithms.
A property class for workspaces.
Exception for errors associated with the instrument definition.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
The concrete, templated class for properties.
virtual std::string value() const =0
Returns the value of the property as a string.
This is helper algorithm used to preprocess detector's positions namely to perform generic part of th...
bool isDetInfoLost(const Mantid::API::MatrixWorkspace_const_sptr &inWS2D) const
function checks if source workspace still has information about detectors.
void updateMasksState(const API::MatrixWorkspace_const_sptr &inputWS, DataObjects::TableWorkspace_sptr &targWS)
Method updates the column, which describes if current detector/spectra is masked It is used if one tr...
void buildFakeDetectorsPositions(const API::MatrixWorkspace_const_sptr &inputWS, DataObjects::TableWorkspace_sptr &targWS)
method calculates fake detectors positions in the situation when real detector information has been l...
std::shared_ptr< DataObjects::TableWorkspace > createTableWorkspace(const API::MatrixWorkspace_const_sptr &inputWS)
helper method to create resulting table workspace
bool m_getIsMasked
the variable specifies if one needs to return the state of detector mask e.g if the detector is maske...
double getEi(const API::MatrixWorkspace_const_sptr &inputWS) const
Method returns the efixed or Ei value stored in properties of the input workspace.
bool m_getEFixed
the variable specifies if one needs to calculate efixed for detectors (make sense for indirect instru...
void init() override
Initialize the algorithm's properties.
void processDetectorsPositions(const API::MatrixWorkspace_const_sptr &inputWS, DataObjects::TableWorkspace_sptr &targWS)
method does preliminary calculations of the detectors positions to convert results into k-dE space ; ...
void exec() override
Virtual method - must be overridden by concrete algorithm.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< Parameter > Parameter_sptr
Typedef for the shared pointer.
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.
Generate a tableworkspace to store the calibration results.
@ Input
An input workspace.
@ Output
An output workspace.