Mantid
Loading...
Searching...
No Matches
VesuvioCalculateGammaBackground.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
11
18
21
26
28using namespace API;
29using namespace Kernel;
30using namespace CurveFitting;
31using namespace CurveFitting::Functions;
32using namespace std;
33using std::placeholders::_1;
34
35// Subscription
36DECLARE_ALGORITHM(VesuvioCalculateGammaBackground)
37
38namespace {
40size_t NTHETA = 5;
42size_t NUP = 5;
43
45double DEG2RAD = M_PI / 180.0;
47double ABSORB_WAVELENGTH = 1.83618;
49specnum_t FORWARD_SCATTER_SPECMIN = 135;
51specnum_t FORWARD_SCATTER_SPECMAX = 198;
52} // namespace
53
54//--------------------------------------------------------------------------------------------------------
55// Public members
56//--------------------------------------------------------------------------------------------------------
57
59VesuvioCalculateGammaBackground::VesuvioCalculateGammaBackground()
60 : Algorithm(), m_inputWS(), m_indices(), m_profileFunction(), m_npeaks(0), m_reversed(), m_samplePos(), m_l1(0.0),
61 m_foilRadius(0.0), m_foilUpMin(0.0), m_foilUpMax(0.0), m_foils0(), m_foils1(), m_backgroundWS(), m_correctedWS() {
62}
63
65VesuvioCalculateGammaBackground::~VesuvioCalculateGammaBackground() { m_indices.clear(); }
66
67//--------------------------------------------------------------------------------------------------------
68// Private members
69//--------------------------------------------------------------------------------------------------------
70
71const std::string VesuvioCalculateGammaBackground::name() const { return "VesuvioCalculateGammaBackground"; }
72
73int VesuvioCalculateGammaBackground::version() const { return 1; }
74
75const std::string VesuvioCalculateGammaBackground::category() const {
76 return "CorrectionFunctions\\BackgroundCorrections";
77}
78
79void VesuvioCalculateGammaBackground::init() {
80
81 auto wsValidator = std::make_shared<CompositeValidator>();
82 wsValidator->add<WorkspaceUnitValidator>("TOF");
83 wsValidator->add<HistogramValidator>(false); // point data
84 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input, wsValidator),
85 "An input workspace containing TOF data");
86
87 declareProperty(std::make_unique<API::FunctionProperty>("ComptonFunction", Direction::InOut),
88 "Function that is able to compute the mass spectrum for the input data"
89 "This will usually be the output from the Fitting");
90
91 declareProperty(std::make_unique<ArrayProperty<int>>("WorkspaceIndexList"),
92 "Indices of the spectra to include in the correction. If "
93 "provided, the output only include these spectra\n"
94 "(Default: all spectra from input)");
95
96 declareProperty(std::make_unique<WorkspaceProperty<>>("BackgroundWorkspace", "", Direction::Output),
97 "A new workspace containing the calculated background.");
98 declareProperty(std::make_unique<WorkspaceProperty<>>("CorrectedWorkspace", "", Direction::Output),
99 "A new workspace containing the calculated background subtracted from "
100 "the input.");
101}
102
103void VesuvioCalculateGammaBackground::exec() {
106
107 const auto nhist = static_cast<int64_t>(m_indices.size());
108 const int64_t nreports = 10 + nhist * (m_npeaks + 2 * m_foils0.size() * NTHETA * NUP * m_npeaks);
109 m_progress = std::make_unique<Progress>(this, 0.0, 1.0, nreports);
110
112 for (int64_t i = 0; i < nhist; ++i) {
114 const size_t outputIndex = i;
115 auto indexIter = m_indices.cbegin();
116 std::advance(indexIter, i);
117 const size_t inputIndex = indexIter->second;
118
119 if (!calculateBackground(inputIndex, outputIndex)) {
120 g_log.information("No detector defined for index=" + std::to_string(inputIndex) + ". Skipping correction.");
121 }
122
124 }
126
127 setProperty("BackgroundWorkspace", m_backgroundWS);
128 setProperty("CorrectedWorkspace", m_correctedWS);
129}
130
139bool VesuvioCalculateGammaBackground::calculateBackground(const size_t inputIndex, const size_t outputIndex) {
140 // Copy X values
141 m_backgroundWS->setSharedX(outputIndex, m_inputWS->sharedX(inputIndex));
142 m_correctedWS->setSharedX(outputIndex, m_inputWS->sharedX(inputIndex));
143 // Copy errors to corrected
144 m_correctedWS->setSharedE(outputIndex, m_inputWS->sharedE(inputIndex));
145
146 try {
147 const auto &inSpec = m_inputWS->getSpectrum(inputIndex);
148 const specnum_t spectrumNo(inSpec.getSpectrumNo());
149 m_backgroundWS->getSpectrum(outputIndex).copyInfoFrom(inSpec);
150 m_correctedWS->getSpectrum(outputIndex).copyInfoFrom(inSpec);
151
152 if (spectrumNo >= FORWARD_SCATTER_SPECMIN && spectrumNo <= FORWARD_SCATTER_SPECMAX) {
153 applyCorrection(inputIndex, outputIndex);
154 } else {
155 g_log.information("Spectrum " + std::to_string(spectrumNo) +
156 " not in forward scatter range. Skipping correction.");
157 // Leave background at 0 and just copy data to corrected
158 m_correctedWS->setSharedY(outputIndex, m_inputWS->sharedY(inputIndex));
159 }
160 return true;
161 } catch (Exception::NotFoundError &) {
162 return false;
163 }
164}
165
174void VesuvioCalculateGammaBackground::applyCorrection(const size_t inputIndex, const size_t outputIndex) {
175 m_progress->report("Computing TOF from detector");
176
177 // results go straight in m_correctedWS to save memory allocations
178 calculateSpectrumFromDetector(inputIndex, outputIndex);
179
180 m_progress->report("Computing TOF foils");
181 // Output goes to m_background to save memory allocations
182 calculateBackgroundFromFoils(inputIndex, outputIndex);
183
184 m_progress->report("Computing correction to input");
185 // Compute total counts from input data, (detector-foil) contributions
186 // assume constant binning
187 const size_t nbins = m_correctedWS->blocksize();
188 const auto &inY = m_inputWS->y(inputIndex);
189 auto &detY = m_correctedWS->mutableY(outputIndex);
190 auto &foilY = m_backgroundWS->mutableY(outputIndex);
191 const double deltaT = m_correctedWS->x(outputIndex)[1] - m_correctedWS->x(outputIndex)[0];
192
193 double dataCounts(0.0), simulCounts(0.0);
194 for (size_t j = 0; j < nbins; ++j) {
195 dataCounts += inY[j] * deltaT;
196 simulCounts += (detY[j] - foilY[j]) * deltaT;
197 }
198
199 // Now corrected for the calculated background
200 const double corrFactor = dataCounts / simulCounts;
201 if (g_log.is(Logger::Priority::PRIO_INFORMATION))
202 g_log.information() << "Correction factor for background=" << corrFactor << "\n";
203
204 for (size_t j = 0; j < nbins; ++j) {
205 // m_backgroundWS already contains the foil values, careful not to overwrite
206 // them
207 double &foilValue = foilY[j]; // non-const reference
208 foilValue *= corrFactor;
209 detY[j] = (inY[j] - foilValue);
210 }
211}
212
219void VesuvioCalculateGammaBackground::calculateSpectrumFromDetector(const size_t inputIndex, const size_t outputIndex) {
220 // -- Setup detector & resolution parameters --
224
225 // Compute a time of flight spectrum convolved with a Voigt resolution
226 // function for each mass
227 // at the detector point & sum to a single spectrum
228 auto &ctdet = m_correctedWS->mutableY(outputIndex);
229 std::vector<double> tmpWork(ctdet.size());
230 ctdet = calculateTofSpectrum(ctdet.rawData(), tmpWork, outputIndex, detPar, detRes);
231 // Correct for distance to the detector: 0.5/l2^2
232 const double detDistCorr = 0.5 / detPar.l2 / detPar.l2;
233 std::transform(ctdet.begin(), ctdet.end(), ctdet.begin(), std::bind(std::multiplies<double>(), _1, detDistCorr));
234}
235
243void VesuvioCalculateGammaBackground::calculateBackgroundFromFoils(const size_t inputIndex, const size_t outputIndex) {
244 // -- Setup detector & resolution parameters --
248
249 const size_t nxvalues = m_backgroundWS->blocksize();
250 std::vector<double> foilSpectrum(nxvalues);
251 auto &ctfoil = m_backgroundWS->mutableY(outputIndex);
252
253 // Compute (C1 - C0) where C1 is counts in pos 1 and C0 counts in pos 0
254 assert(m_foils0.size() == m_foils1.size());
255 for (size_t i = 0; i < m_foils0.size(); ++i) {
256 foilSpectrum.assign(nxvalues, 0.0);
257 calculateBackgroundSingleFoil(foilSpectrum, outputIndex, m_foils1[i], detPar.pos, detPar, detRes);
258 // sum spectrum values from first position
259 std::transform(ctfoil.begin(), ctfoil.end(), foilSpectrum.begin(), ctfoil.begin(), std::plus<double>());
260
261 foilSpectrum.assign(nxvalues, 0.0);
262 calculateBackgroundSingleFoil(foilSpectrum, outputIndex, m_foils0[i], detPar.pos, detPar, detRes);
263 // subtract spectrum values from zeroth position
264 std::transform(ctfoil.begin(), ctfoil.end(), foilSpectrum.begin(), ctfoil.begin(), std::minus<double>());
265 }
266 bool reversed = (m_reversed.count(m_inputWS->getSpectrum(inputIndex).getSpectrumNo()) != 0);
267 // This is quicker than the if within the loop
268 if (reversed) {
269 // The reversed ones should be (C0 - C1)
270 std::transform(ctfoil.begin(), ctfoil.end(), ctfoil.begin(), std::bind(std::multiplies<double>(), _1, -1.0));
271 }
272}
273
287void VesuvioCalculateGammaBackground::calculateBackgroundSingleFoil(std::vector<double> &ctfoil, const size_t wsIndex,
288 const FoilInfo &foilInfo, const V3D &detPos,
289 const DetectorParams &detPar,
290 const ResolutionParams &detRes) {
296 const double thetaStep = (foilInfo.thetaMax - foilInfo.thetaMin) / static_cast<double>(NTHETA);
297 const double thetaStepRad = thetaStep * DEG2RAD;
298 const double upStep = (m_foilUpMax - m_foilUpMin) / static_cast<double>(NUP);
299 const double elementArea = abs(m_foilRadius * upStep * thetaStepRad);
300 V3D elementPos; // reusable vector for computing distances
301
302 // Structs to hold geometry & resolution information
303 DetectorParams foilPar = detPar; // copy
304 foilPar.t0 = 0.0;
305 CurveFitting::Functions::ResolutionParams foilRes = detRes; // copy
306 foilRes.dEnGauss = foilInfo.gaussWidth;
307 foilRes.dEnLorentz = foilInfo.lorentzWidth;
308
309 const size_t nvalues = ctfoil.size();
310 std::vector<double> singleElement(nvalues), tmpWork(nvalues);
311
312 for (size_t i = 0; i < NTHETA; ++i) {
313 double thetaZeroRad = (foilInfo.thetaMin + (static_cast<double>(i) + 0.5) * thetaStep) * DEG2RAD;
314 elementPos.setZ(m_foilRadius * cos(thetaZeroRad));
315 elementPos.setX(m_foilRadius * sin(thetaZeroRad));
316 for (size_t j = 0; j < NUP; ++j) {
317 double ypos = m_foilUpMin + (static_cast<double>(j) + 0.5) * upStep;
318 elementPos.setY(ypos);
319 foilPar.l2 = m_samplePos.distance(elementPos);
320 foilPar.theta = acos(m_foilRadius * cos(thetaZeroRad) / foilPar.l2); // scattering angle in radians
321
322 // Spectrum for this position
323 singleElement.assign(nvalues, 0.0);
324 singleElement = calculateTofSpectrum(singleElement, tmpWork, wsIndex, foilPar, foilRes);
325
326 // Correct for absorption & distance
327 const double den = (elementPos.Z() * cos(thetaZeroRad) + elementPos.X() * sin(thetaZeroRad));
328 const double absorbFactor = 1.0 / (1.0 - exp(-ABSORB_WAVELENGTH * foilPar.l2 / den));
329 const double elemDetDist = elementPos.distance(detPos);
330 const double distFactor = elementArea / (4.0 * M_PI * foilPar.l2 * foilPar.l2 * elemDetDist * elemDetDist);
331 // Add on to other contributions
332 for (size_t k = 0; k < nvalues; ++k) {
333 ctfoil[k] += singleElement[k] * absorbFactor * distFactor;
334 }
335 }
336 }
337}
338
348std::vector<double> VesuvioCalculateGammaBackground::calculateTofSpectrum(const std::vector<double> &inSpectrum,
349 std::vector<double> &tmpWork,
350 const size_t wsIndex,
351 const DetectorParams &detpar,
352 const ResolutionParams &respar) {
353 assert(inSpectrum.size() == tmpWork.size());
354
355 // Assumes the input is in seconds, transform it temporarily
356 auto &tseconds = m_backgroundWS->mutableX(wsIndex);
357 std::transform(tseconds.begin(), tseconds.end(), tseconds.begin(), std::bind(std::multiplies<double>(), _1, 1e-6));
358
359 // retrieveInputs ensures we will get a composite function and that each
360 // member is a ComptonProfile
361 // we can't static_cast though due to the virtual inheritance with IFunction
362 auto profileFunction =
363 std::dynamic_pointer_cast<CompositeFunction>(FunctionFactory::Instance().createInitialized(m_profileFunction));
364
365 std::vector<double> correctedVals(inSpectrum);
366
367 for (size_t i = 0; i < m_npeaks; ++i) {
368 auto profile = std::dynamic_pointer_cast<CurveFitting::Functions::ComptonProfile>(profileFunction->getFunction(i));
369 profile->disableLogging();
370 profile->setUpForFit();
371
372 // Fix the Mass parameter
373 profile->fix(0);
374
375 profile->cacheYSpaceValues(m_backgroundWS->points(wsIndex), detpar, respar);
376
377 profile->massProfile(tmpWork.data(), tmpWork.size());
378 // Add to final result
379
380 std::transform(correctedVals.begin(), correctedVals.end(), tmpWork.begin(), correctedVals.begin(),
381 std::plus<double>());
382 m_progress->report();
383 }
384 // Put X back microseconds
385 std::transform(tseconds.begin(), tseconds.end(), tseconds.begin(), std::bind(std::multiplies<double>(), _1, 1e6));
386 return correctedVals;
387}
388
392void VesuvioCalculateGammaBackground::retrieveInputs() {
393 m_inputWS = getProperty("InputWorkspace");
394 m_profileFunction = getPropertyValue("ComptonFunction");
395 if (m_profileFunction.find(';') == std::string::npos) // not composite
396 {
397 m_profileFunction = "composite=CompositeFunction;" + m_profileFunction;
398 }
399
400 IFunction_sptr profileFunction = FunctionFactory::Instance().createInitialized(m_profileFunction);
401 if (auto composite = std::dynamic_pointer_cast<CompositeFunction>(profileFunction)) {
402 m_npeaks = composite->nFunctions();
403 for (size_t i = 0; i < m_npeaks; ++i) {
404 auto single = std::dynamic_pointer_cast<CurveFitting::Functions::ComptonProfile>(composite->getFunction(i));
405 if (!single) {
406 throw std::invalid_argument("Invalid function. Composite must contain "
407 "only ComptonProfile functions");
408 }
409 }
410 } else {
411 throw std::invalid_argument("Invalid function found. Expected ComptonFunction to contain a "
412 "composite of ComptonProfiles or a single ComptonProfile.");
413 }
414
415 // Spectrum numbers whose calculation of background from foils is reversed
416 m_reversed.clear();
417 for (specnum_t i = 143; i < 199; ++i) {
418 if ((i >= 143 && i <= 150) || (i >= 159 && i <= 166) || (i >= 175 && i <= 182) || (i >= 191 && i <= 198))
419 m_reversed.insert(i);
420 }
421
422 // Workspace indices mapping input->output
423 m_indices.clear();
424 std::vector<int> requestedIndices = getProperty("WorkspaceIndexList");
425 if (requestedIndices.empty()) {
426 for (size_t i = 0; i < m_inputWS->getNumberHistograms(); ++i) {
427 m_indices.emplace(i, i); // 1-to-1
428 }
429 } else {
430 for (size_t i = 0; i < requestedIndices.size(); ++i) {
431 m_indices.emplace(i, static_cast<size_t>(requestedIndices[i])); // user-requested->increasing on output
432 }
433 }
434
436}
437
441void VesuvioCalculateGammaBackground::createOutputWorkspaces() {
442 const size_t nhist = m_indices.size();
445}
446
447void VesuvioCalculateGammaBackground::cacheInstrumentGeometry() {
448 auto inst = m_inputWS->getInstrument();
449 auto refFrame = inst->getReferenceFrame();
450 auto upAxis = refFrame->pointingUp();
451 auto source = inst->getSource();
452 auto sample = inst->getSample();
453 m_samplePos = sample->getPos();
454 m_l1 = m_samplePos.distance(source->getPos());
455
456 // foils
457 auto changer = std::dynamic_pointer_cast<const Geometry::IObjComponent>(inst->getComponentByName("foil-changer"));
458 if (!changer) {
459 throw std::invalid_argument("Input workspace has no component named foil-changer. "
460 "One is required to define integration area.");
461 }
462
463 // 'height' of box sets limits in beam direction
464 Geometry::BoundingBox boundBox;
465 changer->getBoundingBox(boundBox);
466 m_foilUpMin = boundBox.minPoint()[upAxis];
467 m_foilUpMax = boundBox.maxPoint()[upAxis];
468
469 // foil geometry
470 // there should be the same number in each position
471 const auto &pmap = m_inputWS->constInstrumentParameters();
472 auto foils0 = inst->getAllComponentsWithName("foil-pos0");
473 auto foils1 = inst->getAllComponentsWithName("foil-pos1");
474 const size_t nfoils = foils0.size();
475 if (nfoils != foils1.size()) {
476 std::ostringstream os;
477 os << "Mismatch in number of foils between pos 0 & 1: pos0=" << nfoils << ", pos1=" << foils1.size();
478 throw std::runtime_error(os.str());
479 }
480 // It is assumed that the foils all lie on a circle of the same radius from
481 // the sample position
482 auto firstFoilPos = foils0[0]->getPos();
483 double dummy(0.0);
484 firstFoilPos.getSpherical(m_foilRadius, dummy, dummy);
485
486 // Cache min/max theta values
487 m_foils0.resize(nfoils);
488 m_foils1.resize(nfoils);
489 for (size_t i = 0; i < nfoils; ++i) {
490 const auto &foil0 = foils0[i];
491 auto thetaRng0 = calculateThetaRange(foil0, m_foilRadius, refFrame->pointingHorizontal());
492 FoilInfo descr;
493 descr.thetaMin = thetaRng0.first;
494 descr.thetaMax = thetaRng0.second;
495 descr.lorentzWidth = ConvertToYSpace::getComponentParameter(*foil0, pmap, "hwhm_lorentz");
496 descr.gaussWidth = ConvertToYSpace::getComponentParameter(*foil0, pmap, "sigma_gauss");
497 m_foils0[i] = descr; // copy
498
499 const auto &foil1 = foils1[i];
500 auto thetaRng1 = calculateThetaRange(foil1, m_foilRadius, refFrame->pointingHorizontal());
501 descr.thetaMin = thetaRng1.first;
502 descr.thetaMax = thetaRng1.second;
503 descr.lorentzWidth = ConvertToYSpace::getComponentParameter(*foil1, pmap, "hwhm_lorentz");
504 descr.gaussWidth = ConvertToYSpace::getComponentParameter(*foil1, pmap, "sigma_gauss");
505 m_foils1[i] = descr; // copy
506 }
507
508 if (g_log.is(Kernel::Logger::Priority::PRIO_INFORMATION)) {
509 std::ostringstream os;
510 os << "Instrument geometry:\n"
511 << " l1 = " << m_l1 << "m\n"
512 << " foil radius = " << m_foilRadius << "\n"
513 << " foil integration min = " << m_foilUpMin << "\n"
514 << " foil integration max = " << m_foilUpMax << "\n";
515 std::ostringstream secondos;
516 for (size_t i = 0; i < nfoils; ++i) {
517 const auto &descr0 = m_foils0[i];
518 os << " foil theta range in position 0: theta_min=" << descr0.thetaMin << ", theta_max=" << descr0.thetaMax
519 << "\n";
520 const auto &descr1 = m_foils1[i];
521 secondos << " foil theta range in position 1: theta_min=" << descr1.thetaMin << ", theta_max=" << descr1.thetaMax
522 << "\n";
523 }
524 g_log.information() << os.str() << secondos.str();
525 }
526}
527
536std::pair<double, double>
537VesuvioCalculateGammaBackground::calculateThetaRange(const Geometry::IComponent_const_sptr &foilComp,
538 const double radius, const unsigned int horizDir) const {
539 auto shapedObject = std::dynamic_pointer_cast<const Geometry::IObjComponent>(foilComp);
540 if (!shapedObject) {
541 throw std::invalid_argument("A foil has been defined without a shape. "
542 "Please check instrument definition.");
543 }
544
545 // First get current theta position
546 auto pos = foilComp->getPos();
547 double theta(0.0), dummy(0.0);
548 pos.getSpherical(dummy, theta, dummy); // absolute angle values
549 if (pos[horizDir] < 0.0)
550 theta *= -1.0; // negative quadrant for theta
551
552 // Compute dtheta from bounding box & radius
553 const auto &box = shapedObject->shape()->getBoundingBox();
554 // box has center at 0,0,0
555 double xmax = box.maxPoint()[0];
556 double dtheta = std::asin(xmax / radius) * 180.0 / M_PI; // degrees
557 return std::make_pair(theta - dtheta, theta + dtheta);
558}
559
560} // namespace Mantid::CurveFitting::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
Definition: MultiThreaded.h:94
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
double radius
Definition: Rasterize.cpp:31
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Kernel::Logger & g_log
Definition: Algorithm.h:451
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
static DetectorParams getDetectorParameters(const API::MatrixWorkspace_const_sptr &ws, const size_t index)
Creates a POD struct containing the required detector parameters for this spectrum.
static double getComponentParameter(const Geometry::IComponent &det, const Geometry::ParameterMap &pmap, const std::string &name)
Retrieve a component parameter.
void calculateBackgroundFromFoils(const size_t inputIndex, const size_t outputIndex)
Compute the expected background from the foils.
double m_foilRadius
Radius of (imaginary) circle that foils sit on.
std::set< specnum_t > m_reversed
List of spectra numbers whose background sum is to be reversed.
void calculateBackgroundSingleFoil(std::vector< double > &ctfoil, const size_t wsIndex, const FoilInfo &foilInfo, const Kernel::V3D &detPos, const DetectorParams &detPar, const CurveFitting::Functions::ResolutionParams &detRes)
Compute expected background from single foil for spectrum at wsIndex.
void applyCorrection(const size_t inputIndex, const size_t outputIndex)
Calculate & correct the given index of the input workspace.
std::vector< FoilInfo > m_foils0
Description of foils in the position 0.
std::vector< FoilInfo > m_foils1
Description of foils in the position 0.
std::unique_ptr< API::Progress > m_progress
Pointer to progress reporting.
double m_foilUpMax
Minimum in up dir to stop integration over foil volume.
std::unordered_map< size_t, size_t > m_indices
Sorted indices to correct.
void cacheInstrumentGeometry()
Compute & store the parameters that are fixed during the correction.
std::vector< double > calculateTofSpectrum(const std::vector< double > &inSpectrum, std::vector< double > &tmpWork, const size_t wsIndex, const DetectorParams &detpar, const CurveFitting::Functions::ResolutionParams &respar)
Compute a TOF spectrum for the given inputs & spectrum.
void calculateSpectrumFromDetector(const size_t inputIndex, const size_t outputIndex)
Compute the expected spectrum from a given detector.
std::string m_profileFunction
Function that defines the mass profile.
API::MatrixWorkspace_sptr m_backgroundWS
Stores the value of the calculated background.
std::pair< double, double > calculateThetaRange(const Geometry::IComponent_const_sptr &foilComp, const double radius, const unsigned int horizDir) const
Compute the theta range for a given foil.
double m_foilUpMin
Minimum in up dir to start integration over foil volume.
bool calculateBackground(size_t inputIndex, size_t outputIndex)
Avoid nested try catch in openmp loop by returning boolean if spectrum was corrceted.
static ResolutionParams getResolutionParameters(const API::MatrixWorkspace_const_sptr &ws, const size_t index)
Creates a POD struct containing the required resolution parameters for this spectrum.
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition: BoundingBox.h:34
const Kernel::V3D & minPoint() const
Returns the min point of the box.
Definition: BoundingBox.h:90
const Kernel::V3D & maxPoint() const
Returns the min point of the box.
Definition: BoundingBox.h:92
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
Exception for when an item is not found in a collection.
Definition: Exception.h:145
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
bool is(int level) const
Returns true if at least the given log level is set.
Definition: Logger.cpp:146
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Class for 3D vectors.
Definition: V3D.h:34
double distance(const V3D &v) const noexcept
Calculates the distance between two vectors.
Definition: V3D.h:287
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
void setZ(const double zz) noexcept
Set is z position.
Definition: V3D.h:230
void setX(const double xx) noexcept
Set is x position.
Definition: V3D.h:218
void setY(const double yy) noexcept
Set is y position.
Definition: V3D.h:224
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
Definition: IComponent.h:161
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
Definition: MultiThreaded.h:22
int32_t specnum_t
Typedef for a spectrum Number.
Definition: IDTypes.h:16
Generate a tableworkspace to store the calibration results.
STL namespace.
std::string to_string(const wide_integer< Bits, Signed > &n)
Simple data structure to store nominal detector values It avoids some functions taking a huge number ...
double theta
scattering angle in radians
double l2
sample-detector distance in metres
Simple data structure to store resolution parameter values It avoids some functions taking a huge num...
double dEnLorentz
lorentz width in energy (meV)
double dEnGauss
gaussian width in energy (meV
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54