Skip to content
Snippets Groups Projects
Commit b7502e79 authored by LamarMoore's avatar LamarMoore Committed by Lamar Moore
Browse files

Moved TofEvent to Mantid::Types re 20436

parent b608ed5d
No related branches found
No related tags found
No related merge requests found
#ifndef MANTID_TYPES_TOFEVENT_H
#define MANTID_TYPES_TOFEVENT_H
#include "MantidTypes/DateAndTime.h"
namespace Mantid {
namespace Types {
//==========================================================================================
/** Info about a single neutron detection event:
*
* - the time of flight of the neutron (can be converted to other units)
* - the absolute time of the pulse at which it was produced
*/
#pragma pack(push, 4) // Ensure the structure is no larger than it needs to
class _declspec(dllexport) TofEvent {
/// EventList has the right to mess with TofEvent.
friend class EventList;
friend class WeightedEvent;
friend class WeightedEventNoTime;
friend class tofGreaterOrEqual;
friend class tofGreater;
friend class DataHandling::LoadEventNexus; // Needed while the ISIS hack of
// spreading events out in a bin
// remains
protected:
/** The 'x value' of the event. This will be in a unit available from the
* UnitFactory.
* Initially (prior to any unit conversion on the holding workspace), this
* will have
* the unit of time-of-flight in microseconds.
*/
double m_tof;
/**
* The absolute time of the start of the pulse that generated this event.
* This is saved as the number of ticks (1 nanosecond if boost is compiled
* for nanoseconds) since a specified epoch: we use the GPS epoch of Jan 1,
*1990.
*
* 64 bits gives 1 ns resolution up to +- 292 years around 1990. Should be
*enough.
*/
DateAndTime m_pulsetime;
public:
/// Constructor, specifying only the time of flight in microseconds
TofEvent(double tof);
/// Constructor, specifying the time of flight in microseconds and the frame
/// id
TofEvent(double tof, const Mantid::Types::DateAndTime pulsetime);
/// Empty constructor
TofEvent();
bool operator==(const TofEvent &rhs) const;
bool operator<(const TofEvent &rhs) const;
bool operator<(const double rhs_tof) const;
bool operator>(const TofEvent &rhs) const;
bool equals(const TofEvent &rhs, const double tolTof,
const int64_t tolPulse) const;
double operator()() const;
double tof() const;
Mantid::Types::DateAndTime pulseTime() const;
double weight() const;
double error() const;
double errorSquared() const;
/// Output a string representation of the event to a stream
friend std::ostream &operator<<(std::ostream &os, const TofEvent &event);
};
#pragma pack(pop)
//==========================================================================================
// TofEvent inlined member function definitions
//==========================================================================================
/** () operator: return the tof (X value) of the event.
* This is useful for std operations like comparisons and std::lower_bound
* @return :: double, the tof (X value) of the event.
*/
inline double TofEvent::operator()() const { return m_tof; }
/** @return The 'x value'. Despite the name, this can be in any unit in the
* UnitFactory.
* If it is time-of-flight, it will be in microseconds.
*/
inline double TofEvent::tof() const { return m_tof; }
/// Return the pulse time
inline Mantid::Types::DateAndTime TofEvent::pulseTime() const {
return m_pulsetime;
}
/// Return the weight of the event - exactly 1.0 always
inline double TofEvent::weight() const { return 1.0; }
/// Return the error of the event - exactly 1.0 always
inline double TofEvent::error() const { return 1.0; }
/// Return the errorSquared of the event - exactly 1.0 always
inline double TofEvent::errorSquared() const { return 1.0; }
} // namespace Types
} // namespace Mantid
#endif // MANTIS_TYPES_TOFEVENT_H
\ No newline at end of file
#include "MantidTypes/TofEvents.h"
namespace Mantid {
namespace Types {
//==========================================================================
/// --------------------- TofEvent stuff ----------------------------------
//==========================================================================
/** Constructor, specifying the time of flight only
* @param tof :: time of flight, in microseconds
*/
TofEvent::TofEvent(const double tof) : m_tof(tof), m_pulsetime(0) {}
/** Constructor, specifying the time of flight and the frame id
* @param tof :: time of flight, in microseconds
* @param pulsetime :: absolute pulse time of the neutron.
*/
TofEvent::TofEvent(const double tof, const DateAndTime pulsetime)
: m_tof(tof), m_pulsetime(pulsetime) {}
/// Empty constructor
TofEvent::TofEvent() : m_tof(0), m_pulsetime(0) {}
/** Comparison operator.
* @param rhs: the other TofEvent to compare.
* @return true if the TofEvent's are identical.*/
bool TofEvent::operator==(const TofEvent &rhs) const {
return (this->m_tof == rhs.m_tof) && (this->m_pulsetime == rhs.m_pulsetime);
}
/** < comparison operator, using the TOF to do the comparison.
* @param rhs: the other TofEvent to compare.
* @return true if this->m_tof < rhs.m_tof*/
bool TofEvent::operator<(const TofEvent &rhs) const {
return (this->m_tof < rhs.m_tof);
}
/** < comparison operator, using the TOF to do the comparison.
* @param rhs: the other TofEvent to compare.
* @return true if this->m_tof < rhs.m_tof*/
bool TofEvent::operator>(const TofEvent &rhs) const {
return (this->m_tof > rhs.m_tof);
}
/** < comparison operator, using the TOF to do the comparison.
* @param rhs_tof: the other time of flight to compare.
* @return true if this->m_tof < rhs.m_tof*/
bool TofEvent::operator<(const double rhs_tof) const {
return (this->m_tof < rhs_tof);
}
/**
* Compare two events within the specified tolerance
*
* @param rhs the other TofEvent to compare
* @param tolTof the tolerance of a difference in m_tof.
* @param tolPulse the tolerance of a difference in m_pulsetime
* in nanoseconds.
*
* @return True if the are the same within the specifed tolerances
*/
bool TofEvent::equals(const TofEvent &rhs, const double tolTof,
const int64_t tolPulse) const {
// compare m_tof
if (std::fabs(this->m_tof - rhs.m_tof) > tolTof)
return false;
// then it is just if the pulse-times are equal
return (this->m_pulsetime.equals(rhs.m_pulsetime, tolPulse));
}
/** Output a string representation of the event to a stream
* @param os :: Stream
* @param event :: TofEvent to output to the stream
*/
ostream &operator<<(ostream &os, const TofEvent &event) {
os << event.m_tof << "," << event.m_pulsetime.toSimpleString();
return os;
}
} // namespace Types
} // namespace Mantid
\ No newline at end of file
......@@ -2,13 +2,13 @@
#define TOFEVENTTEST_H_ 1
#include <cxxtest/TestSuite.h>
#include "MantidDataObjects/Events.h"
#include "MantidTypes/TofEvent.h"
#include "MantidKernel/Timer.h"
#include <cmath>
using namespace Mantid;
using namespace Mantid::Kernel;
using namespace Mantid::DataObjects;
using namespace Mantid::Types
using std::runtime_error;
using std::size_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment