Skip to content

Commit 75614ab

Browse files
Merge pull request #38121 from mantidproject/remove-prompt-pulse
Fix for Remove prompt pulse bug into ornl-next
2 parents 91b9a55 + 1cf5781 commit 75614ab

File tree

9 files changed

+93
-14
lines changed

9 files changed

+93
-14
lines changed

Framework/Algorithms/inc/MantidAlgorithms/RemovePromptPulse.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class MANTID_ALGORITHMS_DLL RemovePromptPulse : public API::Algorithm {
4343
/// Try to get the frequency from a given name.
4444
double getFrequency(const API::Run &run);
4545
void getTofRange(const API::MatrixWorkspace_const_sptr &wksp, double &tmin, double &tmax);
46-
std::vector<double> calculatePulseTimes(const double tmin, const double tmax, const double period);
46+
std::vector<double> calculatePulseTimes(const double tmin, const double tmax, const double period,
47+
const double width);
4748
};
4849

4950
} // namespace Algorithms

Framework/Algorithms/src/RemovePromptPulse.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void RemovePromptPulse::exec() {
133133
g_log.information() << "Data tmin=" << tmin << ", tmax=" << tmax << ", period=" << period << " microseconds\n";
134134

135135
// calculate the times for the prompt pulse
136-
std::vector<double> pulseTimes = this->calculatePulseTimes(tmin, tmax, period);
136+
std::vector<double> pulseTimes = this->calculatePulseTimes(tmin, tmax, period, width);
137137
if (pulseTimes.empty()) {
138138
g_log.notice() << "Not applying filter since prompt pulse is not in data "
139139
"range (period = "
@@ -198,13 +198,17 @@ double RemovePromptPulse::getFrequency(const API::Run &run) {
198198
* @param tmin The minimum time-of-flight measured.
199199
* @param tmax The maximum time-of-flight measured.
200200
* @param period The accelerator period.
201+
* @param width The width of the time of flight (in microseconds) to remove from the data.
201202
* @return A vector of all prompt pulse times possible within the time-of-flight
202203
* range.
203204
*/
204-
std::vector<double> RemovePromptPulse::calculatePulseTimes(const double tmin, const double tmax, const double period) {
205+
std::vector<double> RemovePromptPulse::calculatePulseTimes(const double tmin, const double tmax, const double period,
206+
const double width) {
205207
std::vector<double> times;
206208
double time = 0.;
207-
209+
// zero pulse should be taken into account
210+
if (tmin > 0 && tmin < width)
211+
times.emplace_back(time);
208212
// find when the first prompt pulse would be
209213
while (time < tmin)
210214
time += period;

Framework/Algorithms/test/RemovePromptPulseTest.h

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ class RemovePromptPulseTest : public CxxTest::TestSuite {
3232
std::string inWSName;
3333
std::string outWSName;
3434

35-
void makeFakeEventWorkspace(const std::string &wsName) {
35+
void makeFakeEventWorkspace(const std::string &wsName, int shift = 0) {
3636
// Make an event workspace with 2 events in each bin.
3737
EventWorkspace_sptr test_in =
3838
WorkspaceCreationHelper::createEventWorkspace(NUMPIXELS, NUMBINS, NUMEVENTS, 1000., BIN_DELTA, 2);
3939
// Fake a TOF unit in the data.
4040
test_in->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
41+
for (size_t i = 0; i < test_in->dataX(0).size(); ++i) {
42+
test_in->dataX(0)[i] += shift;
43+
}
4144
test_in->setInstrument(ComponentCreationHelper::createTestInstrumentCylindrical(NUMPIXELS / 9));
4245
// Make sure the detector IDs are ok
4346
for (int i = 0; i < NUMPIXELS; i++)
@@ -92,14 +95,16 @@ class RemovePromptPulseTest : public CxxTest::TestSuite {
9295
return;
9396

9497
// Verify the results
95-
// drop events 36 spectra, 2 events/bin, 10 bins/pulse, 9 pulses
96-
TS_ASSERT_EQUALS(num_events - 36 * 2 * 10 * 9, ws->getNumberEvents());
98+
// drop events 36 spectra, 2 events/bin, 10 bins/pulse, 10 pulses
99+
TS_ASSERT_EQUALS(num_events - 36 * 2 * 10 * 10, ws->getNumberEvents());
100+
101+
std::cout << "num_events = " << ws->getNumberEvents() << std::endl;
97102

98103
AnalysisDataService::Instance().remove(inWSName);
99104
AnalysisDataService::Instance().remove(outWSName);
100105
}
101106

102-
void test_exec_hit() {
107+
void test_exec_hit_tmin() {
103108
inWSName = "RemovePromptPulseTest_InputWS_hit";
104109
outWSName = inWSName; //"RemovePromptPulseTest_OutputWS_hit";
105110
this->makeFakeEventWorkspace(inWSName);
@@ -131,4 +136,72 @@ class RemovePromptPulseTest : public CxxTest::TestSuite {
131136
// Clean up
132137
AnalysisDataService::Instance().remove(inWSName);
133138
}
139+
140+
void test_exec_miss_tmin() {
141+
inWSName = "RemovePromptPulseTest_InputWS_miss_tmin";
142+
outWSName = "RemovePromptPulseTest_OutputWS_miss_tmin";
143+
this->makeFakeEventWorkspace(inWSName, -1100);
144+
145+
EventWorkspace_sptr ws;
146+
TS_ASSERT_THROWS_NOTHING(ws = AnalysisDataService::Instance().retrieveWS<EventWorkspace>(inWSName));
147+
std::size_t num_events = ws->getNumberEvents();
148+
RemovePromptPulse alg;
149+
TS_ASSERT_THROWS_NOTHING(alg.initialize())
150+
TS_ASSERT(alg.isInitialized())
151+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("InputWorkspace", inWSName));
152+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", outWSName));
153+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Width", "1000."));
154+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Frequency", "100"));
155+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("TMin", "-100"));
156+
157+
TS_ASSERT_THROWS_NOTHING(alg.execute(););
158+
TS_ASSERT(alg.isExecuted());
159+
160+
// Retrieve the workspace from data service.
161+
TS_ASSERT_THROWS_NOTHING(ws = AnalysisDataService::Instance().retrieveWS<EventWorkspace>(outWSName));
162+
TS_ASSERT(ws);
163+
if (!ws)
164+
return;
165+
166+
// Verify the results
167+
// drop events 36 spectra, 2 events/bin, 10 bins/pulse, 10 pulses
168+
TS_ASSERT_EQUALS(num_events - 36 * 2 * 10 * 10, ws->getNumberEvents());
169+
170+
AnalysisDataService::Instance().remove(inWSName);
171+
AnalysisDataService::Instance().remove(outWSName);
172+
}
173+
174+
void test_exec_hit_negative_tmin() {
175+
inWSName = "RemovePromptPulseTest_InputWS_tmin";
176+
outWSName = inWSName;
177+
this->makeFakeEventWorkspace(inWSName, -1100);
178+
179+
EventWorkspace_sptr ws;
180+
TS_ASSERT_THROWS_NOTHING(ws = AnalysisDataService::Instance().retrieveWS<EventWorkspace>(inWSName));
181+
std::size_t num_events = ws->getNumberEvents();
182+
183+
RemovePromptPulse alg;
184+
TS_ASSERT_THROWS_NOTHING(alg.initialize())
185+
TS_ASSERT(alg.isInitialized())
186+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("InputWorkspace", inWSName));
187+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", outWSName));
188+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Width", "1000."));
189+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Frequency", "200"));
190+
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("TMin", "-100"));
191+
192+
TS_ASSERT_THROWS_NOTHING(alg.execute(););
193+
TS_ASSERT(alg.isExecuted());
194+
195+
// Retrieve the workspace from data service. TODO: Change to your desired
196+
// type
197+
TS_ASSERT_THROWS_NOTHING(ws = AnalysisDataService::Instance().retrieveWS<EventWorkspace>(outWSName));
198+
TS_ASSERT(ws);
199+
if (!ws)
200+
return;
201+
202+
// Verify the results
203+
TS_ASSERT(num_events > ws->getNumberEvents()); // should drop events
204+
// Clean up
205+
AnalysisDataService::Instance().remove(inWSName);
206+
}
134207
};

Framework/WorkflowAlgorithms/test/AlignAndFocusPowderTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,9 @@ class AlignAndFocusPowderTest : public CxxTest::TestSuite {
786786
if (m_compressStartTime != "0")
787787
align_and_focus.setProperty("CompressStartTime", m_compressStartTime);
788788

789-
// Remove prompt pulse; will cutoff last 6 long-TOF peaks (freq is 200 Hz)
789+
// Remove prompt pulse; will cutoff the first peak from 6 long-TOF peaks (freq is 200 Hz)
790790
if (m_removePromptPulse)
791-
align_and_focus.setProperty("RemovePromptPulseWidth", 1e4);
791+
align_and_focus.setProperty("RemovePromptPulseWidth", 2200.0);
792792

793793
// Filter absorption resonances - default unit is wavelength
794794
align_and_focus.setPropertyValue("ResonanceFilterLowerLimits", m_filterResonanceLower);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
04a9f44a284a43beb22647d4e7f3ad6e
1+
abedd395d477ae260a181debe077bdb1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bd4e49926e46e2c516a0ca4e2e1cff2b
1+
6c2cfb5a54df48ed2644fb1ed1a380f7
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1b7d2fd46c0a8db3ee057405ecef9045
1+
1987860075f1fbeddcc408e09dc3208f
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f16afe97ddec63a0b275ee11bbfb1977
1+
21df458d01d9851fd0e0c436a50a9c4d
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- :ref:`RemovePromptPulse <algm-RemovePromptPulse>` has been fixed to correctly account for the first pulse.

0 commit comments

Comments
 (0)