25using namespace Kernel;
27using namespace DataObjects;
28using namespace Geometry;
29using Types::Event::TofEvent;
35 std::make_shared<WorkspaceUnitValidator>(
"TOF")),
36 "Workspace to apply the TOF correction to");
39 "Time of flight of fastest neutrons from the lead pulse, in "
45 "If True, use path from moderator to individual pixel instead"
46 "of to center of the detector panel",
48 declareProperty(
"DetectorName",
"detector1",
"Name of the double panel");
53 const size_t numHists = inputWS->getNumberHistograms();
56 const double pulsePeriod =
getProperty(
"PulsePeriod");
58 const double frameWidth =
getProperty(
"FrameWidth");
59 const bool isFrameSkipping =
getProperty(
"FrameSkipping");
60 const bool pathToPixel =
getProperty(
"PathToPixel");
61 const std::string detectorName =
getProperty(
"DetectorName");
63 const auto &spectrumInfo = inputWS->spectrumInfo();
64 const auto msd = spectrumInfo.l1();
65 auto ins = inputWS->getInstrument();
66 auto mdd = msd + ins->getComponentByName(detectorName)->getDistance(*(ins->getSample()));
69 struct correctTofFactory {
71 explicit correctTofFactory(
double pulsePeriod,
double minTOF,
double frameWidth,
bool isFrameSkipping)
72 : m_pulsePeriod(pulsePeriod), m_minTOF(minTOF), m_frameWidth(frameWidth), m_isFrameSkipping(isFrameSkipping) {
76 const double nf = std::floor(minTOF / frameWidth);
77 m_framesOffsetTime = frameWidth * nf;
80 double operator()(
const double tof,
const double pathToPixelFactor = 1.0)
const {
82 double newTOF = tof + m_framesOffsetTime;
85 double scaledMinTOF = m_minTOF * pathToPixelFactor;
86 if (newTOF < scaledMinTOF)
87 newTOF += m_frameWidth;
89 if (m_isFrameSkipping && newTOF > scaledMinTOF + m_pulsePeriod)
90 newTOF += m_pulsePeriod;
97 double m_framesOffsetTime;
98 bool m_isFrameSkipping;
101 auto correctTof = correctTofFactory(pulsePeriod, minTOF, frameWidth, isFrameSkipping);
105 for (int64_t ispec = 0; ispec < int64_t(numHists); ++ispec) {
107 if (!spectrumInfo.hasDetectors(ispec)) {
108 g_log.
warning() <<
"Workspace index " << ispec <<
" has no detector assigned to it - discarding\n";
111 EventList &evlist = inputWS->getSpectrum(ispec);
117 double pathToPixelFactor(1.0);
119 pathToPixelFactor = (msd + spectrumInfo.l2(ispec)) / mdd;
121 auto tofCorrector = std::bind(correctTof, std::placeholders::_1, pathToPixelFactor);
124 progress.report(
"Correct TOF frame");
129 inputWS->resetAllXToSingleBin();
#define DECLARE_ALGORITHM(classname)
#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...
#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.
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
A property class for workspaces.
void exec() override
Execution code.
EQSANSCorrectFrame()
Default constructor.
void init() override
Initialisation code.
std::size_t getNumberEvents() const override
Return the number of events in the list.
void convertTof(std::function< double(double)> func, const int sorting=0) override
void warning(const std::string &msg)
Logs at warning level.
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
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.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.