Unverified Commit 1e924cdb authored by Nick Draper's avatar Nick Draper Committed by GitHub
Browse files

Merge pull request #27428 from martyngigg/fix_performance_tests

Fix performance tests
parents 055c344a de1c8ba0
......@@ -367,7 +367,7 @@ private:
"name=LinearBackground, A0=101.3, A1=8510.3;"
"name=Gaussian, PeakCentre=0.1, Height=200000, Sigma=0.007;"
"name=Lorentzian, PeakCentre=0.45, Amplitude=6000, FWHM=0.017;"
"name=PseudoVoigt, PeakCentre=0.75, Height=85050, FWHM=0.04;"
"name=PseudoVoigt, PeakCentre=0.75, Intensity=85050, FWHM=0.04;"
"name=Gaussian, PeakCentre=0.95, Height=110000, Sigma=0.007;"
"name=Gaussian, PeakCentre=1.15, Height=110000, Sigma=0.007;"
"name=BackToBackExponential, X0=1.30, I=7000, A=1500.1, B=1800.2, "
......
......@@ -126,7 +126,6 @@ set(SRC_FILES
src/LoadSwans.cpp
src/LoadTBL.cpp
src/LoadTOFRawNexus.cpp
src/LoadVulcanCalFile.cpp
src/MaskDetectors.cpp
src/MaskDetectorsInShape.cpp
src/MaskSpectra.cpp
......@@ -325,7 +324,6 @@ set(INC_FILES
inc/MantidDataHandling/LoadSwans.h
inc/MantidDataHandling/LoadTBL.h
inc/MantidDataHandling/LoadTOFRawNexus.h
inc/MantidDataHandling/LoadVulcanCalFile.h
inc/MantidDataHandling/MaskDetectors.h
inc/MantidDataHandling/MaskDetectorsInShape.h
inc/MantidDataHandling/MaskSpectra.h
......@@ -517,7 +515,6 @@ set(TEST_FILES
LoadTBLTest.h
LoadTOFRawNexusTest.h
LoadTest.h
LoadVulcanCalFileTest.h
MaskDetectorsInShapeTest.h
MaskDetectorsTest.h
MaskSpectraTest.h
......
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef MANTID_DATAHANDLING_LOADVULCANCALFILE_H_
#define MANTID_DATAHANDLING_LOADVULCANCALFILE_H_
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IAlgorithm.h"
#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidDataObjects/GroupingWorkspace.h"
#include "MantidDataObjects/MaskWorkspace.h"
#include "MantidDataObjects/OffsetsWorkspace.h"
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/System.h"
#include "MantidDataObjects/EventWorkspace.h"
namespace Mantid {
namespace DataHandling {
enum VULCAN_OFFSET_LEVEL {
VULCAN_OFFSET_BANK,
VULCAN_OFFSET_MODULE,
VULCAN_OFFSET_STACK
};
/** Algorithm to load a 5-column ascii .cal file into up to 3 workspaces:
* a GroupingWorkspace, OffsetsWorkspace and/or MaskWorkspace.
*/
class DLLExport LoadVulcanCalFile : public API::Algorithm {
public:
/// Algorithm's name for identification
const std::string name() const override { return "LoadVulcanCalFile"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "Loads set of VULCAN's offset files into up to 3 workspaces: a "
"GroupingWorkspace, OffsetsWorkspace and/or MaskWorkspace.";
}
/// Algorithm's version for identification
int version() const override { return 1; }
const std::vector<std::string> seeAlso() const override {
return {"ReadGroupsFromFile", "CreateDummyCalFile",
"CreateCalFileByNames", "AlignDetectors",
"DiffractionFocussing", "LoadCalFile",
"SaveCalFile", "MergeCalFiles"};
}
/// Algorithm's category for identification
const std::string category() const override {
return "DataHandling\\Text;Diffraction\\DataHandling";
}
void getInstrument3WaysInit();
Geometry::Instrument_const_sptr getInstrument();
static void readCalFile(const std::string &calFileName,
Mantid::DataObjects::GroupingWorkspace_sptr groupWS,
Mantid::DataObjects::OffsetsWorkspace_sptr offsetsWS,
Mantid::DataObjects::MaskWorkspace_sptr maskWS);
private:
/// Initialise the properties
void init() override;
/// Run the algorithm
void exec() override;
void processInOutProperites();
/// Set up grouping workspace
void setupGroupingWorkspace();
/// Set up mask workspace
void setupMaskWorkspace();
void generateOffsetsWorkspace();
/// Read VULCAN's offset file
void readOffsetFile(std::map<detid_t, double> &map_detoffset);
void processOffsets(std::map<detid_t, double> map_detoffset);
/// Convert offsets from VUCLAN's offset to Mantid's
void convertOffsets();
Geometry::Instrument_const_sptr m_instrument;
/// Type of grouping
VULCAN_OFFSET_LEVEL m_groupingType{VULCAN_OFFSET_BANK};
std::string m_offsetFilename;
std::string m_badPixFilename;
DataObjects::OffsetsWorkspace_sptr m_tofOffsetsWS;
DataObjects::OffsetsWorkspace_sptr m_offsetsWS;
DataObjects::GroupingWorkspace_sptr m_groupWS;
DataObjects::MaskWorkspace_sptr m_maskWS;
// Verification tool
void alignEventWorkspace();
bool m_doAlignEventWS{false};
DataObjects::EventWorkspace_sptr m_eventWS;
// Map for bank: eff_L and theta (in degree)
std::map<int, std::pair<double, double>> m_effLTheta;
};
} // namespace DataHandling
} // namespace Mantid
#endif /* MANTID_DATAHANDLING_LOADVULCANCALFILE_H_ */
This diff is collapsed.
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef MANTID_DATAHANDLING_LOCALVULCANCALFILETEST_H_
#define MANTID_DATAHANDLING_LOCALVULCANCALFILETEST_H_
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/SpectrumInfo.h"
#include "MantidDataHandling/LoadVulcanCalFile.h"
#include "MantidDataObjects/GroupingWorkspace.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid::DataHandling;
using namespace Mantid::DataObjects;
using namespace Mantid::API;
class LoadVulcanCalFileTest : public CxxTest::TestSuite {
public:
void test_Init() {
LoadVulcanCalFile alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize())
TS_ASSERT(alg.isInitialized())
}
void no_test_exec() {
// Name of the output workspace.
std::string outWSName("LoadVulcanCalFileTest");
std::string offsetfilename = "pid_offset_vulcan_new.dat";
LoadVulcanCalFile alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize())
TS_ASSERT(alg.isInitialized())
TS_ASSERT_THROWS_NOTHING(
alg.setPropertyValue("OffsetFilename", offsetfilename));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Grouping", "6Modules"));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("WorkspaceName", outWSName));
TS_ASSERT_THROWS_NOTHING(
alg.setPropertyValue("BankIDs", "21,22,23,26,27,28"));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue(
"EffectiveDIFCs", "16372.601900,16376.951300,16372.096300,16336.622200,"
"16340.822400,16338.777300"));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue(
"Effective2Thetas",
"90.091000,90.122000,90.089000,89.837000,89.867000,89.852000"));
TS_ASSERT_THROWS_NOTHING(alg.execute(););
TS_ASSERT(alg.isExecuted());
// Retrieve the workspace from data service. TODO: Change to your desired
// type
GroupingWorkspace_sptr groupWS;
TS_ASSERT_THROWS_NOTHING(
groupWS = AnalysisDataService::Instance().retrieveWS<GroupingWorkspace>(
outWSName + "_group"));
TS_ASSERT(groupWS);
if (!groupWS)
return;
TS_ASSERT_EQUALS(groupWS->getNumberHistograms(), 7392);
TS_ASSERT_EQUALS(int(groupWS->y(0)[0]), 1);
TS_ASSERT_EQUALS(int(groupWS->y(7391)[0]), 6);
// Check if filename is saved
TS_ASSERT_EQUALS(alg.getPropertyValue("OffsetFilename"),
groupWS->run().getProperty("Filename")->value());
OffsetsWorkspace_sptr offsetsWS;
TS_ASSERT_THROWS_NOTHING(
offsetsWS =
AnalysisDataService::Instance().retrieveWS<OffsetsWorkspace>(
outWSName + "_offsets"));
TS_ASSERT(offsetsWS);
if (!offsetsWS)
return;
TS_ASSERT_DELTA(offsetsWS->getValue(26250), -0.000472175, 1e-7);
TS_ASSERT_DELTA(offsetsWS->y(7391)[0], 6.39813e-05, 1e-7);
// Check if filename is saved
TS_ASSERT_EQUALS(alg.getPropertyValue("OffsetFilename"),
offsetsWS->run().getProperty("Filename")->value());
// Masking
SpecialWorkspace2D_sptr maskWS;
TS_ASSERT_THROWS_NOTHING(
maskWS = AnalysisDataService::Instance().retrieveWS<SpecialWorkspace2D>(
outWSName + "_mask"));
TS_ASSERT(maskWS);
if (!maskWS)
return;
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName + "_group");
AnalysisDataService::Instance().remove(outWSName + "_offsets");
AnalysisDataService::Instance().remove(outWSName + "_mask");
AnalysisDataService::Instance().remove(outWSName + "_TOF_offsets");
return;
}
void no_test_exec2BanksBadPixel() {
// Name of the output workspace.
std::string outWSName("LoadVulcanCalFileTest");
std::string offsetfilename = "pid_offset_vulcan_new.dat";
std::string badpixelfilename = "bad_pids_vulcan_new_6867_7323.dat";
LoadVulcanCalFile alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize())
TS_ASSERT(alg.isInitialized())
TS_ASSERT_THROWS_NOTHING(
alg.setPropertyValue("OffsetFilename", offsetfilename));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Grouping", "2Banks"));
TS_ASSERT_THROWS_NOTHING(
alg.setPropertyValue("BadPixelFilename", badpixelfilename));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("WorkspaceName", outWSName));
TS_ASSERT_THROWS_NOTHING(
alg.setPropertyValue("BankIDs", "21,22,23,26,27,28"));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue(
"EffectiveDIFCs", "16376.951300,16376.951300,16376.951300, "
"16340.822400,16340.822400,16340.822400"));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue(
"Effective2Thetas",
"90.122000,90.122000,90.122000, 89.867000,89.867000,89.867000"));
TS_ASSERT_THROWS_NOTHING(alg.execute(););
TS_ASSERT(alg.isExecuted());
// Retrieve the workspace from data service. TODO: Change to your desired
// type
GroupingWorkspace_sptr groupWS;
TS_ASSERT_THROWS_NOTHING(
groupWS = AnalysisDataService::Instance().retrieveWS<GroupingWorkspace>(
outWSName + "_group"));
TS_ASSERT(groupWS);
if (!groupWS)
return;
TS_ASSERT_EQUALS(int(groupWS->getValue(26410)), 1);
TS_ASSERT_EQUALS(int(groupWS->getValue(34298)), 2);
// Masking
SpecialWorkspace2D_sptr maskWS;
TS_ASSERT_THROWS_NOTHING(
maskWS = AnalysisDataService::Instance().retrieveWS<SpecialWorkspace2D>(
outWSName + "_mask"));
TS_ASSERT(maskWS);
if (!maskWS)
return;
const auto &spectrumInfo = maskWS->spectrumInfo();
size_t nummasked = 0;
for (size_t i = 0; i < maskWS->getNumberHistograms(); ++i) {
if (maskWS->y(i)[0] > 0.5) {
++nummasked;
TS_ASSERT(spectrumInfo.isMasked(i));
}
}
TS_ASSERT_EQUALS(nummasked, 6);
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName + "_group");
AnalysisDataService::Instance().remove(outWSName + "_offsets");
AnalysisDataService::Instance().remove(outWSName + "_mask");
AnalysisDataService::Instance().remove(outWSName + "_TOF_offsets");
return;
}
};
class LoadVulcanCalFileTestPerformance : public CxxTest::TestSuite {
public:
void setUp() override {
for (int i = 0; i < numberOfIterations; ++i) {
loadAlgPtrs.emplace_back(setupAlg());
}
}
void testLoadVulcanCalFilePerformance() {
for (auto alg : loadAlgPtrs) {
TS_ASSERT_THROWS_NOTHING(alg->execute());
}
}
void tearDown() override {
for (int i = 0; i < numberOfIterations; i++) {
delete loadAlgPtrs[i];
loadAlgPtrs[i] = nullptr;
}
Mantid::API::AnalysisDataService::Instance().remove(outWSName);
}
private:
std::vector<LoadVulcanCalFile *> loadAlgPtrs;
const int numberOfIterations = 1;
const std::string offsetfilename = "pid_offset_vulcan_new.dat";
const std::string outWSName = "vulcan_cal_file_ws";
const std::string effectiveDFCs = "16372.601900,16376.951300,16372.096300,"
"16336.622200, 16340.822400,16338.777300";
const std::string effective2Thetas =
"90.091000,90.122000,90.089000,89.837000,89.867000,89.852000";
LoadVulcanCalFile *setupAlg() {
LoadVulcanCalFile *loader = new LoadVulcanCalFile;
loader->initialize();
loader->isInitialized();
loader->setPropertyValue("OffsetFilename", offsetfilename);
loader->setPropertyValue("WorkspaceName", outWSName);
loader->setPropertyValue("OffsetFilename", offsetfilename);
loader->setPropertyValue("Grouping", "6Modules");
loader->setPropertyValue("WorkspaceName", outWSName);
loader->setPropertyValue("BankIDs", "21,22,23,26,27,28");
loader->setPropertyValue("EffectiveDIFCs", effectiveDFCs);
loader->setPropertyValue("Effective2Thetas", effective2Thetas);
loader->setRethrows(true);
return loader;
}
};
#endif /* MANTID_DATAHANDLING_LOCALVULCANCALFILETEST_H_ */
.. algorithm::
.. summary::
.. relatedalgorithms::
.. properties::
Description
-----------
This algorithm loads a set of VULCAN's calibration files, including
detector offset file and bad pixel file, and convert VULCAN's offset
on time-of-flight to Mantid's offset on d-spacing.
By this algorithm, Vulcan's calibration file can be converted to
the standard calibration file for SNSPowderReduction.
Detector offset file
####################
There are :math:`62500` (:math:`50\times 1250`) rows in the offset file.
In each row, the first value is the pixel ID; and the second is inner-module offset.
For each module, it starts from row :math:`1250\times M_{i}`, where :math:`M_{i}` is the module ID starting
from 0.
- Line :math:`1250\times M_i + 0`: pixel ID, offset (first detector in module)
- Line :math:`1250\times M_i + 1`: pixel ID, offset
- ... ...
- Line :math:`1250\times M_i + 1231`: pixle ID, offset (last detector in module)
- Line :math:`1250\times M_i + 1232`: pixel ID, offset (detector is not used)
- ... ...
- Line :math:`1250\times M_i + 1248`: pixel ID, inter module correction
- Line :math:`1250\times M_i + 1249`: pixel ID, inter bank correction
Bad pixel file
##############
In bad pixel file, each line contains one and only one integer
corresponding to the detector ID of a bad pixel.
The bad pixels will be masked in the output MaskWorkspace.
Conversion from offset in TOF to d-spacing
##########################################
With VULCAN's offsets in TOF, the calibration is done as the following.
- Total offset is the product of innter-bank offset, inner-module offset and inter-module offset
.. math:: \log_{10}(\xi) = \log_{10}(\xi_0) + \log_{10}(\xi_1) + \log_{10}(\xi_2)
- Time-of-flight value of each neutron is obtained by division of total offset.
.. math:: \log_{10}(T') = \log_{10}(T) - \log_{10}(\xi)
.. math:: T' = \frac{T}{\xi}`
where (1) :math:`\xi_0` is the inner-bank correction, (2) :math:`\xi_1` is the inner module (inter-bank) correction,
and (3) :math:`\xi_2` is the inter-module (inner-pack) correction.
Be noticed that the correction factor recorded in VULCAN's offset file is :math:`\log(\xi)`.
Thus if we define :math:`\Xi = \log(\xi)`, then time focussing formula used by VUCLAN's IDL code
is :math:`T^{(f)} = \frac{T}{10^{\Xi}}`
Therefore, by defining :math:`\xi^{(v)}` as the VULCAN's offset, and :math:`\xi^{(m)}` as
the Mantid's offset, then we can convert VULCAN's offset to Mantid's as
.. math:: \xi^{(m)} = \frac{L\cdot\sin\theta}{L'\cdot\sin\theta'}\cdot\frac{1}{\xi^{(m)}} - 1
VULCAN uses effective DIFC and :math:`2\theta` for the effective detector to be focussed on.
It follows the Bragg rule for time-of-flight, i.e.,
.. math:: T = DIFC \cdot d = (252.777\cdot L\cdot 2\cdot\sin\theta)\cdot d
Usage
-----
.. testcode:: LoadVulcanCalFile
print ("LoadVulcanCalFile is obsolete and will be deprecated soon")
.. testcleanup::
Output:
.. testoutput:: LoadVulcanCalFile
LoadVulcanCalFile is obsolete and will be deprecated soon
.. categories::
.. sourcelink::
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment