Mantid
Loading...
Searching...
No Matches
Events.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 +
12#include <cmath>
13#include <functional>
14#include <stdexcept>
15
16using std::ostream;
17using std::size_t;
18
19namespace Mantid::DataObjects {
20using Types::Event::TofEvent;
21
22//==========================================================================
24//==========================================================================
25
29WeightedEvent::WeightedEvent(double time_of_flight) : TofEvent(time_of_flight), m_weight(1.0), m_errorSquared(1.0) {}
30
37WeightedEvent::WeightedEvent(double tof, const Mantid::Types::Core::DateAndTime pulsetime, double weight,
38 double errorSquared)
39 : TofEvent(tof, pulsetime), m_weight(static_cast<float>(weight)), m_errorSquared(static_cast<float>(errorSquared)) {
40}
41
48WeightedEvent::WeightedEvent(double tof, const Mantid::Types::Core::DateAndTime pulsetime, float weight,
49 float errorSquared)
50 : TofEvent(tof, pulsetime), m_weight(weight), m_errorSquared(errorSquared) {}
51
57WeightedEvent::WeightedEvent(const TofEvent &rhs, double weight, double errorSquared)
58 : TofEvent(rhs.m_tof, rhs.m_pulsetime), m_weight(static_cast<float>(weight)),
59 m_errorSquared(static_cast<float>(errorSquared)) {}
60
66WeightedEvent::WeightedEvent(const TofEvent &rhs, float weight, float errorSquared)
67 : TofEvent(rhs.m_tof, rhs.m_pulsetime), m_weight(weight), m_errorSquared(errorSquared) {}
68
73 : TofEvent(rhs.m_tof, rhs.m_pulsetime), m_weight(1.0), m_errorSquared(1.0) {}
74
76WeightedEvent::WeightedEvent() : TofEvent(), m_weight(1.0), m_errorSquared(1.0) {}
77
83 return (this->m_tof == rhs.m_tof) && (this->m_pulsetime == rhs.m_pulsetime) && (this->m_weight == rhs.m_weight) &&
84 (this->m_errorSquared == rhs.m_errorSquared);
85}
86
99bool WeightedEvent::equals(const WeightedEvent &rhs, const double tolTof, const double tolWeight,
100 const int64_t tolPulse) const {
101 if (std::fabs(this->m_tof - rhs.m_tof) > tolTof)
102 return false;
103 if (std::fabs(this->m_weight - rhs.m_weight) > tolWeight)
104 return false;
105 if (std::fabs(this->m_errorSquared - rhs.m_errorSquared) > tolWeight)
106 return false;
107 // then it is just if the pulse-times are equal
108 return (this->m_pulsetime.equals(rhs.m_pulsetime, tolPulse));
109}
110
115ostream &operator<<(ostream &os, const WeightedEvent &event) {
116 os << event.m_tof << "," << event.m_pulsetime.toSimpleString() << " (W" << event.m_weight << " +- " << event.error()
117 << ")";
118 return os;
119}
120
121//==========================================================================
123//==========================================================================
124
129 : m_tof(time_of_flight), m_weight(1.0), m_errorSquared(1.0) {}
130
136WeightedEventNoTime::WeightedEventNoTime(double tof, double weight, double errorSquared)
137 : m_tof(tof), m_weight(static_cast<float>(weight)), m_errorSquared(static_cast<float>(errorSquared)) {}
138
144WeightedEventNoTime::WeightedEventNoTime(double tof, float weight, float errorSquared)
145 : m_tof(tof), m_weight(weight), m_errorSquared(errorSquared) {}
146
153WeightedEventNoTime::WeightedEventNoTime(double tof, const Mantid::Types::Core::DateAndTime /*unused*/, double weight,
154 double errorSquared)
155 : m_tof(tof), m_weight(static_cast<float>(weight)), m_errorSquared(static_cast<float>(errorSquared)) {}
156
163WeightedEventNoTime::WeightedEventNoTime(double tof, const Mantid::Types::Core::DateAndTime /*unused*/, float weight,
164 float errorSquared)
165 : m_tof(tof), m_weight(weight), m_errorSquared(errorSquared) {}
166
172WeightedEventNoTime::WeightedEventNoTime(const TofEvent &rhs, double weight, double errorSquared)
173 : m_tof(rhs.m_tof), m_weight(static_cast<float>(weight)), m_errorSquared(static_cast<float>(errorSquared)) {}
174
180WeightedEventNoTime::WeightedEventNoTime(const TofEvent &rhs, float weight, float errorSquared)
181 : m_tof(rhs.m_tof), m_weight(weight), m_errorSquared(errorSquared) {}
182
187 : m_tof(rhs.m_tof), m_weight(rhs.m_weight), m_errorSquared(rhs.m_errorSquared) {}
188
192WeightedEventNoTime::WeightedEventNoTime(const TofEvent &rhs) : m_tof(rhs.m_tof), m_weight(1.0), m_errorSquared(1.0) {}
193
195WeightedEventNoTime::WeightedEventNoTime() : m_tof(0.0), m_weight(1.0), m_errorSquared(1.0) {}
196
202 return (this->m_tof == rhs.m_tof) && (this->m_weight == rhs.m_weight) && (this->m_errorSquared == rhs.m_errorSquared);
203}
204
215bool WeightedEventNoTime::equals(const WeightedEventNoTime &rhs, const double tolTof, const double tolWeight) const {
216 if (std::fabs(this->m_tof - rhs.m_tof) > tolTof)
217 return false;
218 if (std::fabs(this->m_weight - rhs.m_weight) > tolWeight)
219 return false;
220 if (std::fabs(this->m_errorSquared - rhs.m_errorSquared) > tolWeight)
221 return false;
222 // then it is just if the pulse-times are equal
223 return true;
224}
225
226} // namespace Mantid::DataObjects
const std::vector< double > & rhs
Info about a single neutron detection event, including a weight and error value, but excluding the pu...
Definition: Events.h:91
double m_tof
The 'x value' (e.g. time-of-flight) of this neutron.
Definition: Events.h:100
float m_weight
The weight of this neutron.
Definition: Events.h:104
float m_errorSquared
The SQUARE of the error that this neutron contributes.
Definition: Events.h:107
bool equals(const WeightedEventNoTime &rhs, const double tolTof, const double tolWeight) const
Compare two events within the specified tolerance.
Definition: Events.cpp:215
WeightedEventNoTime()
Empty constructor.
Definition: Events.cpp:195
bool operator==(const WeightedEventNoTime &rhs) const
Comparison operator.
Definition: Events.cpp:201
Info about a single neutron detection event, including a weight and error value:
Definition: Events.h:39
bool equals(const WeightedEvent &rhs, const double tolTof, const double tolWeight, const int64_t tolPulse) const
Compare two events within the specified tolerance.
Definition: Events.cpp:99
float m_errorSquared
The SQUARE of the error that this neutron contributes.
Definition: Events.h:52
float m_weight
The weight of this neutron.
Definition: Events.h:49
bool operator==(const WeightedEvent &rhs) const
Comparison operator.
Definition: Events.cpp:82
WeightedEvent()
Empty constructor.
Definition: Events.cpp:76
MANTID_API_DLL std::ostream & operator<<(std::ostream &, const AlgorithmHistory &)
Prints a text representation.