-
Notifications
You must be signed in to change notification settings - Fork 122
/
ISISCalibration.cpp
713 lines (588 loc) · 25.9 KB
/
ISISCalibration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
#include "MantidQtCustomInterfaces/Indirect/ISISCalibration.h"
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/Logger.h"
#include "MantidAPI/WorkspaceGroup.h"
#include <QFileInfo>
using namespace Mantid::API;
namespace {
Mantid::Kernel::Logger g_log("ISISCalibration");
}
using namespace Mantid::API;
using MantidQt::API::BatchAlgorithmRunner;
namespace MantidQt {
namespace CustomInterfaces {
//----------------------------------------------------------------------------------------------
/** Constructor
*/
ISISCalibration::ISISCalibration(IndirectDataReduction *idrUI, QWidget *parent)
: IndirectDataReductionTab(idrUI, parent), m_lastCalPlotFilename("") {
m_uiForm.setupUi(parent);
DoubleEditorFactory *doubleEditorFactory = new DoubleEditorFactory();
// CAL PROPERTY TREE
m_propTrees["CalPropTree"] = new QtTreePropertyBrowser();
m_propTrees["CalPropTree"]->setFactoryForManager(m_dblManager,
doubleEditorFactory);
m_uiForm.propertiesCalibration->addWidget(m_propTrees["CalPropTree"]);
// Cal Property Tree: Peak/Background
m_properties["CalPeakMin"] = m_dblManager->addProperty("Peak Min");
m_properties["CalPeakMax"] = m_dblManager->addProperty("Peak Max");
m_properties["CalBackMin"] = m_dblManager->addProperty("Back Min");
m_properties["CalBackMax"] = m_dblManager->addProperty("Back Max");
m_propTrees["CalPropTree"]->addProperty(m_properties["CalPeakMin"]);
m_propTrees["CalPropTree"]->addProperty(m_properties["CalPeakMax"]);
m_propTrees["CalPropTree"]->addProperty(m_properties["CalBackMin"]);
m_propTrees["CalPropTree"]->addProperty(m_properties["CalBackMax"]);
// Cal plot range selectors
auto calPeak = m_uiForm.ppCalibration->addRangeSelector("CalPeak");
calPeak->setColour(Qt::red);
auto calBackground =
m_uiForm.ppCalibration->addRangeSelector("CalBackground");
calBackground->setColour(Qt::blue); // blue to be consistent with fit wizard
// RES PROPERTY TREE
m_propTrees["ResPropTree"] = new QtTreePropertyBrowser();
m_propTrees["ResPropTree"]->setFactoryForManager(m_dblManager,
doubleEditorFactory);
m_uiForm.loResolutionOptions->addWidget(m_propTrees["ResPropTree"]);
// Res Property Tree: Spectra Selection
m_properties["ResSpecMin"] = m_dblManager->addProperty("Spectra Min");
m_propTrees["ResPropTree"]->addProperty(m_properties["ResSpecMin"]);
m_dblManager->setDecimals(m_properties["ResSpecMin"], 0);
m_properties["ResSpecMax"] = m_dblManager->addProperty("Spectra Max");
m_propTrees["ResPropTree"]->addProperty(m_properties["ResSpecMax"]);
m_dblManager->setDecimals(m_properties["ResSpecMax"], 0);
// Res Property Tree: Background Properties
QtProperty *resBG = m_grpManager->addProperty("Background");
m_propTrees["ResPropTree"]->addProperty(resBG);
m_properties["ResStart"] = m_dblManager->addProperty("Start");
resBG->addSubProperty(m_properties["ResStart"]);
m_properties["ResEnd"] = m_dblManager->addProperty("End");
resBG->addSubProperty(m_properties["ResEnd"]);
// Res Property Tree: Rebinning
const int NUM_DECIMALS = 3;
QtProperty *resRB = m_grpManager->addProperty("Rebinning");
m_propTrees["ResPropTree"]->addProperty(resRB);
m_properties["ResELow"] = m_dblManager->addProperty("Low");
m_dblManager->setDecimals(m_properties["ResELow"], NUM_DECIMALS);
m_dblManager->setValue(m_properties["ResELow"], -0.2);
resRB->addSubProperty(m_properties["ResELow"]);
m_properties["ResEWidth"] = m_dblManager->addProperty("Width");
m_dblManager->setDecimals(m_properties["ResEWidth"], NUM_DECIMALS);
m_dblManager->setValue(m_properties["ResEWidth"], 0.002);
m_dblManager->setMinimum(m_properties["ResEWidth"], 0.001);
resRB->addSubProperty(m_properties["ResEWidth"]);
m_properties["ResEHigh"] = m_dblManager->addProperty("High");
m_dblManager->setDecimals(m_properties["ResEHigh"], NUM_DECIMALS);
m_dblManager->setValue(m_properties["ResEHigh"], 0.2);
resRB->addSubProperty(m_properties["ResEHigh"]);
// Res plot range selectors
// Create ResBackground first so ResPeak is drawn above it
auto resBackground = m_uiForm.ppResolution->addRangeSelector("ResBackground");
resBackground->setColour(Qt::blue);
auto resPeak = m_uiForm.ppResolution->addRangeSelector("ResPeak");
resPeak->setColour(Qt::red);
// SIGNAL/SLOT CONNECTIONS
// Update instrument information when a new instrument config is selected
connect(this, SIGNAL(newInstrumentConfiguration()), this,
SLOT(setDefaultInstDetails()));
connect(resPeak, SIGNAL(rangeChanged(double, double)), resBackground,
SLOT(setRange(double, double)));
// Update property map when a range selector is moved
connect(calPeak, SIGNAL(minValueChanged(double)), this,
SLOT(calMinChanged(double)));
connect(calPeak, SIGNAL(maxValueChanged(double)), this,
SLOT(calMaxChanged(double)));
connect(calBackground, SIGNAL(minValueChanged(double)), this,
SLOT(calMinChanged(double)));
connect(calBackground, SIGNAL(maxValueChanged(double)), this,
SLOT(calMaxChanged(double)));
connect(resPeak, SIGNAL(minValueChanged(double)), this,
SLOT(calMinChanged(double)));
connect(resPeak, SIGNAL(maxValueChanged(double)), this,
SLOT(calMaxChanged(double)));
connect(resBackground, SIGNAL(minValueChanged(double)), this,
SLOT(calMinChanged(double)));
connect(resBackground, SIGNAL(maxValueChanged(double)), this,
SLOT(calMaxChanged(double)));
// Update range selector positions when a value in the double manager changes
connect(m_dblManager, SIGNAL(valueChanged(QtProperty *, double)), this,
SLOT(calUpdateRS(QtProperty *, double)));
// Plot miniplots after a file has loaded
connect(m_uiForm.leRunNo, SIGNAL(filesFound()), this, SLOT(calPlotRaw()));
// Plot miniplots when the user clicks Plot Raw
connect(m_uiForm.pbPlotRaw, SIGNAL(clicked()), this, SLOT(calPlotRaw()));
// Toggle RES file options when user toggles Create RES File checkbox
connect(m_uiForm.ckCreateResolution, SIGNAL(toggled(bool)), this,
SLOT(resCheck(bool)));
// Shows message on run button when user is inputting a run number
connect(m_uiForm.leRunNo, SIGNAL(fileTextChanged(const QString &)), this,
SLOT(pbRunEditing()));
// Shows message on run button when Mantid is finding the file for a given run
// number
connect(m_uiForm.leRunNo, SIGNAL(findingFiles()), this, SLOT(pbRunFinding()));
// Reverts run button back to normal when file finding has finished
connect(m_uiForm.leRunNo, SIGNAL(fileFindingFinished()), this,
SLOT(pbRunFinished()));
// Nudge resCheck to ensure res range selectors are only shown when Create RES
// file is checked
resCheck(m_uiForm.ckCreateResolution->isChecked());
connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this,
SLOT(algorithmComplete(bool)));
// Handle plotting and saving
connect(m_uiForm.pbSave, SIGNAL(clicked()), this, SLOT(saveClicked()));
connect(m_uiForm.pbPlot, SIGNAL(clicked()), this, SLOT(plotClicked()));
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
ISISCalibration::~ISISCalibration() {}
void ISISCalibration::setup() {}
void ISISCalibration::run() {
// Get properties
QStringList filenameList = m_uiForm.leRunNo->getFilenames();
QString filenames = filenameList.join(",");
QString rawFile = m_uiForm.leRunNo->getFirstFilename();
QFileInfo rawFileInfo(rawFile);
QString name = rawFileInfo.baseName();
auto instDetails = getInstrumentDetails();
QString instDetectorRange =
instDetails["spectra-min"] + "," + instDetails["spectra-max"];
QString peakRange = m_properties["CalPeakMin"]->valueText() + "," +
m_properties["CalPeakMax"]->valueText();
QString backgroundRange = m_properties["CalBackMin"]->valueText() + "," +
m_properties["CalBackMax"]->valueText();
QString outputWorkspaceNameStem =
name + QString::fromStdString("_") +
getInstrumentConfiguration()->getAnalyserName() +
getInstrumentConfiguration()->getReflectionName();
outputWorkspaceNameStem = outputWorkspaceNameStem.toLower();
m_outputCalibrationName = outputWorkspaceNameStem;
if (filenameList.size() > 1)
m_outputCalibrationName += "_multi";
m_outputCalibrationName += "_calib";
bool loadLog = m_uiForm.ckLoadLogFiles->isChecked();
// Configure the calibration algorithm
IAlgorithm_sptr calibrationAlg =
AlgorithmManager::Instance().create("IndirectCalibration");
calibrationAlg->initialize();
calibrationAlg->setProperty("InputFiles", filenames.toStdString());
calibrationAlg->setProperty("OutputWorkspace",
m_outputCalibrationName.toStdString());
calibrationAlg->setProperty("DetectorRange", instDetectorRange.toStdString());
calibrationAlg->setProperty("PeakRange", peakRange.toStdString());
calibrationAlg->setProperty("BackgroundRange", backgroundRange.toStdString());
calibrationAlg->setProperty("LoadLogFiles", loadLog);
if (m_uiForm.ckScale->isChecked()) {
double scale = m_uiForm.spScale->value();
calibrationAlg->setProperty("ScaleFactor", scale);
}
m_batchAlgoRunner->addAlgorithm(calibrationAlg);
// Initially take the calibration workspace as the result
m_pythonExportWsName = m_outputCalibrationName.toStdString();
// Configure the resolution algorithm
if (m_uiForm.ckCreateResolution->isChecked()) {
m_outputResolutionName = outputWorkspaceNameStem;
if (filenameList.size() > 1)
m_outputResolutionName += "_multi";
m_outputResolutionName += "_res";
QString resDetectorRange =
QString::number(m_dblManager->value(m_properties["ResSpecMin"])) + "," +
QString::number(m_dblManager->value(m_properties["ResSpecMax"]));
QString rebinString =
QString::number(m_dblManager->value(m_properties["ResELow"])) + "," +
QString::number(m_dblManager->value(m_properties["ResEWidth"])) + "," +
QString::number(m_dblManager->value(m_properties["ResEHigh"]));
QString background =
QString::number(m_dblManager->value(m_properties["ResStart"])) + "," +
QString::number(m_dblManager->value(m_properties["ResEnd"]));
bool smooth = m_uiForm.ckSmoothResolution->isChecked();
IAlgorithm_sptr resAlg =
AlgorithmManager::Instance().create("IndirectResolution", -1);
resAlg->initialize();
resAlg->setProperty("InputFiles", filenames.toStdString());
resAlg->setProperty(
"Instrument",
getInstrumentConfiguration()->getInstrumentName().toStdString());
resAlg->setProperty(
"Analyser",
getInstrumentConfiguration()->getAnalyserName().toStdString());
resAlg->setProperty(
"Reflection",
getInstrumentConfiguration()->getReflectionName().toStdString());
resAlg->setProperty("RebinParam", rebinString.toStdString());
resAlg->setProperty("DetectorRange", resDetectorRange.toStdString());
resAlg->setProperty("BackgroundRange", background.toStdString());
resAlg->setProperty("LoadLogFiles", loadLog);
if (m_uiForm.ckResolutionScale->isChecked())
resAlg->setProperty("ScaleFactor", m_uiForm.spScale->value());
if (smooth)
resAlg->setProperty("OutputWorkspace",
m_outputResolutionName.toStdString() + "_pre_smooth");
else
resAlg->setProperty("OutputWorkspace",
m_outputResolutionName.toStdString());
m_batchAlgoRunner->addAlgorithm(resAlg);
if (smooth) {
IAlgorithm_sptr smoothAlg =
AlgorithmManager::Instance().create("WienerSmooth");
smoothAlg->initialize();
smoothAlg->setProperty("OutputWorkspace",
m_outputResolutionName.toStdString());
BatchAlgorithmRunner::AlgorithmRuntimeProps smoothAlgInputProps;
smoothAlgInputProps["InputWorkspace"] =
m_outputResolutionName.toStdString() + "_pre_smooth";
m_batchAlgoRunner->addAlgorithm(smoothAlg, smoothAlgInputProps);
}
// When creating resolution file take the resolution workspace as the result
m_pythonExportWsName = m_outputResolutionName.toStdString();
}
m_batchAlgoRunner->executeBatchAsync();
}
/*
* Handle completion of the calibration and resolution algorithms.
*
* @param error If the algorithms failed.
*/
void ISISCalibration::algorithmComplete(bool error) {
if (error)
return;
m_uiForm.pbSave->setEnabled(true);
m_uiForm.pbPlot->setEnabled(true);
}
bool ISISCalibration::validate() {
MantidQt::CustomInterfaces::UserInputValidator uiv;
uiv.checkMWRunFilesIsValid("Run", m_uiForm.leRunNo);
auto peakRange =
std::make_pair(m_dblManager->value(m_properties["CalPeakMin"]),
m_dblManager->value(m_properties["CalPeakMax"]));
auto backRange =
std::make_pair(m_dblManager->value(m_properties["CalBackMin"]),
m_dblManager->value(m_properties["CalBackMax"]));
uiv.checkValidRange("Peak Range", peakRange);
uiv.checkValidRange("Back Range", backRange);
uiv.checkRangesDontOverlap(peakRange, backRange);
if (m_uiForm.ckCreateResolution->isChecked()) {
auto backgroundRange =
std::make_pair(m_dblManager->value(m_properties["ResStart"]),
m_dblManager->value(m_properties["ResEnd"]));
uiv.checkValidRange("Background", backgroundRange);
double eLow = m_dblManager->value(m_properties["ResELow"]);
double eHigh = m_dblManager->value(m_properties["ResEHigh"]);
double eWidth = m_dblManager->value(m_properties["ResEWidth"]);
uiv.checkBins(eLow, eWidth, eHigh);
}
QString error = uiv.generateErrorMessage();
if (error != "")
g_log.warning(error.toStdString());
return (error == "");
}
/**
* Sets default spectra, peak and background ranges.
*/
void ISISCalibration::setDefaultInstDetails() {
// Get spectra, peak and background details
QMap<QString, QString> instDetails = getInstrumentDetails();
// Set the search instrument for runs
m_uiForm.leRunNo->setInstrumentOverride(instDetails["instrument"]);
// Set spectra range
m_dblManager->setValue(m_properties["ResSpecMin"],
instDetails["spectra-min"].toDouble());
m_dblManager->setValue(m_properties["ResSpecMax"],
instDetails["spectra-max"].toDouble());
// Set peak and background ranges
std::map<std::string, double> ranges = getRangesFromInstrument();
QPair<double, double> peakRange(ranges["peak-start-tof"],
ranges["peak-end-tof"]);
QPair<double, double> backgroundRange(ranges["back-start-tof"],
ranges["back-end-tof"]);
auto calPeak = m_uiForm.ppCalibration->getRangeSelector("CalPeak");
auto calBackground =
m_uiForm.ppCalibration->getRangeSelector("CalBackground");
setRangeSelector(calPeak, m_properties["CalPeakMin"],
m_properties["CalPeakMax"], peakRange);
setRangeSelector(calBackground, m_properties["CalBackMin"],
m_properties["CalBackMax"], backgroundRange);
}
/**
* Replots the raw data mini plot and the energy mini plot
*/
void ISISCalibration::calPlotRaw() {
QString filename = m_uiForm.leRunNo->getFirstFilename();
// Don't do anything if the file we would plot has not changed
if (filename == m_lastCalPlotFilename)
return;
m_lastCalPlotFilename = filename;
if (filename.isEmpty()) {
emit showMessageBox("Cannot plot raw data without filename");
return;
}
QFileInfo fi(filename);
QString wsname = fi.baseName();
auto instDetails = getInstrumentDetails();
int specMin = instDetails["spectra-min"].toInt();
int specMax = instDetails["spectra-max"].toInt();
if (!loadFile(filename, wsname, specMin, specMax)) {
emit showMessageBox("Unable to load file.\nCheck whether your file exists "
"and matches the selected instrument in the Energy "
"Transfer tab.");
return;
}
MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve(wsname.toStdString()));
const auto &dataX = input->x(0);
QPair<double, double> range(dataX.front(), dataX.back());
m_uiForm.ppCalibration->clear();
m_uiForm.ppCalibration->addSpectrum("Raw", input, 0);
m_uiForm.ppCalibration->resizeX();
auto calPeak = m_uiForm.ppCalibration->getRangeSelector("CalPeak");
auto calBackground =
m_uiForm.ppCalibration->getRangeSelector("CalBackground");
setPlotPropertyRange(calPeak, m_properties["CalELow"],
m_properties["CalEHigh"], range);
setPlotPropertyRange(calBackground, m_properties["CalStart"],
m_properties["CalEnd"], range);
setDefaultInstDetails();
m_uiForm.ppCalibration->replot();
// Also replot the energy
calPlotEnergy();
}
/**
* Replots the energy mini plot
*/
void ISISCalibration::calPlotEnergy() {
if (!m_uiForm.leRunNo->isValid()) {
emit showMessageBox("Run number not valid.");
return;
}
QString files = m_uiForm.leRunNo->getFilenames().join(",");
QFileInfo fi(m_uiForm.leRunNo->getFirstFilename());
QString detRange =
QString::number(m_dblManager->value(m_properties["ResSpecMin"])) + "," +
QString::number(m_dblManager->value(m_properties["ResSpecMax"]));
IAlgorithm_sptr reductionAlg =
AlgorithmManager::Instance().create("ISISIndirectEnergyTransfer");
reductionAlg->initialize();
reductionAlg->setProperty(
"Instrument",
getInstrumentConfiguration()->getInstrumentName().toStdString());
reductionAlg->setProperty(
"Analyser",
getInstrumentConfiguration()->getAnalyserName().toStdString());
reductionAlg->setProperty(
"Reflection",
getInstrumentConfiguration()->getReflectionName().toStdString());
reductionAlg->setProperty("InputFiles", files.toStdString());
reductionAlg->setProperty("OutputWorkspace",
"__IndirectCalibration_reduction");
reductionAlg->setProperty("SpectraRange", detRange.toStdString());
reductionAlg->setProperty("LoadLogFiles",
m_uiForm.ckLoadLogFiles->isChecked());
reductionAlg->execute();
if (!reductionAlg->isExecuted()) {
g_log.warning("Could not generate energy preview plot.");
return;
}
WorkspaceGroup_sptr reductionOutputGroup =
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
"__IndirectCalibration_reduction");
if (reductionOutputGroup->size() == 0) {
g_log.warning("No result workspaces, cannot plot energy preview.");
return;
}
MatrixWorkspace_sptr energyWs = boost::dynamic_pointer_cast<MatrixWorkspace>(
reductionOutputGroup->getItem(0));
if (!energyWs) {
g_log.warning("No result workspaces, cannot plot energy preview.");
return;
}
const auto &dataX = energyWs->x(0);
QPair<double, double> range(dataX.front(), dataX.back());
auto resBackground = m_uiForm.ppResolution->getRangeSelector("ResBackground");
setPlotPropertyRange(resBackground, m_properties["ResStart"],
m_properties["ResEnd"], range);
m_uiForm.ppResolution->clear();
m_uiForm.ppResolution->addSpectrum("Energy", energyWs, 0);
m_uiForm.ppResolution->resizeX();
calSetDefaultResolution(energyWs);
m_uiForm.ppResolution->replot();
}
/**
* Set default background and rebinning properties for a given instrument
* and analyser
*
* @param ws :: Mantid workspace containing the loaded instrument
*/
void ISISCalibration::calSetDefaultResolution(MatrixWorkspace_const_sptr ws) {
auto inst = ws->getInstrument();
auto analyser = inst->getStringParameter("analyser");
if (analyser.size() > 0) {
auto comp = inst->getComponentByName(analyser[0]);
if (!comp)
return;
auto params = comp->getNumberParameter("resolution", true);
// Set the default instrument resolution
if (params.size() > 0) {
double res = params[0];
// Set default rebinning bounds
QPair<double, double> peakRange(-res * 10, res * 10);
auto resPeak = m_uiForm.ppResolution->getRangeSelector("ResPeak");
setPlotPropertyRange(resPeak, m_properties["ResELow"],
m_properties["ResEHigh"], peakRange);
setRangeSelector(resPeak, m_properties["ResELow"],
m_properties["ResEHigh"], peakRange);
// Set default background bounds
QPair<double, double> backgroundRange(-res * 9, -res * 8);
auto resBackground =
m_uiForm.ppResolution->getRangeSelector("ResBackground");
setRangeSelector(resBackground, m_properties["ResStart"],
m_properties["ResEnd"], backgroundRange);
}
}
}
/**
* Handles a range selector having it's minimum value changed.
* Updates property in property map.
*
* @param val :: New minimum value
*/
void ISISCalibration::calMinChanged(double val) {
auto calPeak = m_uiForm.ppCalibration->getRangeSelector("CalPeak");
auto calBackground =
m_uiForm.ppCalibration->getRangeSelector("CalBackground");
auto resPeak = m_uiForm.ppResolution->getRangeSelector("ResPeak");
auto resBackground = m_uiForm.ppResolution->getRangeSelector("ResBackground");
MantidWidgets::RangeSelector *from =
qobject_cast<MantidWidgets::RangeSelector *>(sender());
if (from == calPeak) {
m_dblManager->setValue(m_properties["CalPeakMin"], val);
} else if (from == calBackground) {
m_dblManager->setValue(m_properties["CalBackMin"], val);
} else if (from == resPeak) {
m_dblManager->setValue(m_properties["ResELow"], val);
} else if (from == resBackground) {
m_dblManager->setValue(m_properties["ResStart"], val);
}
}
/**
* Handles a range selector having it's maximum value changed.
* Updates property in property map.
*
* @param val :: New maximum value
*/
void ISISCalibration::calMaxChanged(double val) {
auto calPeak = m_uiForm.ppCalibration->getRangeSelector("CalPeak");
auto calBackground =
m_uiForm.ppCalibration->getRangeSelector("CalBackground");
auto resPeak = m_uiForm.ppResolution->getRangeSelector("ResPeak");
auto resBackground = m_uiForm.ppResolution->getRangeSelector("ResBackground");
MantidWidgets::RangeSelector *from =
qobject_cast<MantidWidgets::RangeSelector *>(sender());
if (from == calPeak) {
m_dblManager->setValue(m_properties["CalPeakMax"], val);
} else if (from == calBackground) {
m_dblManager->setValue(m_properties["CalBackMax"], val);
} else if (from == resPeak) {
m_dblManager->setValue(m_properties["ResEHigh"], val);
} else if (from == resBackground) {
m_dblManager->setValue(m_properties["ResEnd"], val);
}
}
/**
* Update a range selector given a QtProperty and new value
*
* @param prop :: The property to update
* @param val :: New value for property
*/
void ISISCalibration::calUpdateRS(QtProperty *prop, double val) {
auto calPeak = m_uiForm.ppCalibration->getRangeSelector("CalPeak");
auto calBackground =
m_uiForm.ppCalibration->getRangeSelector("CalBackground");
auto resPeak = m_uiForm.ppResolution->getRangeSelector("ResPeak");
auto resBackground = m_uiForm.ppResolution->getRangeSelector("ResBackground");
if (prop == m_properties["CalPeakMin"])
calPeak->setMinimum(val);
else if (prop == m_properties["CalPeakMax"])
calPeak->setMaximum(val);
else if (prop == m_properties["CalBackMin"])
calBackground->setMinimum(val);
else if (prop == m_properties["CalBackMax"])
calBackground->setMaximum(val);
else if (prop == m_properties["ResStart"])
resBackground->setMinimum(val);
else if (prop == m_properties["ResEnd"])
resBackground->setMaximum(val);
else if (prop == m_properties["ResELow"])
resPeak->setMinimum(val);
else if (prop == m_properties["ResEHigh"])
resPeak->setMaximum(val);
}
/**
* This function enables/disables the display of the options involved in creating
*the RES file.
*
* @param state :: whether checkbox is checked or unchecked
*/
void ISISCalibration::resCheck(bool state) {
m_uiForm.ppResolution->getRangeSelector("ResPeak")->setVisible(state);
m_uiForm.ppResolution->getRangeSelector("ResBackground")->setVisible(state);
// Toggle scale and smooth options
m_uiForm.ckResolutionScale->setEnabled(state);
m_uiForm.ckSmoothResolution->setEnabled(state);
}
/**
* Called when a user starts to type / edit the runs to load.
*/
void ISISCalibration::pbRunEditing() {
emit updateRunButton(false, "Editing...",
"Run numbers are currently being edited.");
}
/**
* Called when the FileFinder starts finding the files.
*/
void ISISCalibration::pbRunFinding() {
emit updateRunButton(
false, "Finding files...",
"Searching for data files for the run numbers entered...");
m_uiForm.leRunNo->setEnabled(false);
}
/**
* Called when the FileFinder has finished finding the files.
*/
void ISISCalibration::pbRunFinished() {
if (!m_uiForm.leRunNo->isValid()) {
emit updateRunButton(
false, "Invalid Run(s)",
"Cannot find data files for some of the run numbers entered.");
} else {
emit updateRunButton();
}
m_uiForm.leRunNo->setEnabled(true);
}
/**
* Handle saving of workspace
*/
void ISISCalibration::saveClicked() {
checkADSForPlotSaveWorkspace(m_outputCalibrationName.toStdString(), false);
addSaveWorkspaceToQueue(m_outputCalibrationName);
if (m_uiForm.ckCreateResolution->isChecked()) {
checkADSForPlotSaveWorkspace(m_outputResolutionName.toStdString(), false);
addSaveWorkspaceToQueue(m_outputResolutionName);
}
m_batchAlgoRunner->executeBatchAsync();
}
/**
* Handle mantid plotting
*/
void ISISCalibration::plotClicked() {
plotTimeBin(m_outputCalibrationName);
checkADSForPlotSaveWorkspace(m_outputCalibrationName.toStdString(), true);
QStringList plotWorkspaces;
if (m_uiForm.ckCreateResolution->isChecked()) {
checkADSForPlotSaveWorkspace(m_outputResolutionName.toStdString(), true);
plotWorkspaces.append(m_outputResolutionName);
if (m_uiForm.ckSmoothResolution->isChecked())
plotWorkspaces.append(m_outputResolutionName + "_pre_smooth");
}
plotSpectrum(plotWorkspaces);
}
} // namespace CustomInterfaces
} // namespace Mantid