-
Notifications
You must be signed in to change notification settings - Fork 122
/
MuonAnalysis.h
500 lines (341 loc) · 14.3 KB
/
MuonAnalysis.h
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
#ifndef MANTIDQTCUSTOMINTERFACES_MUONANALYSIS_H_
#define MANTIDQTCUSTOMINTERFACES_MUONANALYSIS_H_
//----------------------
// Includes
//----------------------
#include "ui_MuonAnalysis.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidGeometry/Instrument.h"
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidQtMantidWidgets/pythonCalc.h"
#include "MantidQtMantidWidgets/MWDiag.h"
#include <map>
namespace MantidQt
{
namespace CustomInterfaces
{
namespace Muon
{
class MuonAnalysisOptionTab;
class MuonAnalysisFitDataTab;
class MuonAnalysisResultTableTab;
}
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Geometry;
/**
This is the main class for the MuonAnalysis interface
see <http://www.mantidproject.org/MuonAnalysis>.
@author Anders Markvardsen, ISIS, RAL
Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MuonAnalysis : public MantidQt::API::UserSubWindow
{
Q_OBJECT
public:
/// Name of the interface
static std::string name() { return "Muon Analysis"; }
// This interface's categories.
static QString categoryInfo() { return "Muon"; }
/// Default Constructor
MuonAnalysis(QWidget *parent = 0);
private slots:
/// Guess Alpha clicked
void guessAlphaClicked();
/// When second period selection combobox changed
void firstPeriodSelectionChanged();
/// When second period selection combobox changed
void secondPeriodSelectionChanged();
/// Input file changed in MWRunFiles widget
void inputFileChanged_MWRunFiles();
// Load current file.
void runLoadCurrent();
/// group table changed
void groupTableChanged(int row, int column);
// group table clicked
void groupTableClicked(int row, int column);
// group table vertical label clicked
void groupTableClicked(int row);
/// group table changed
void pairTableChanged(int row, int column);
// pair table clicked
void pairTableClicked(int row, int column);
// pair table vertical lable clicked
void pairTableClicked(int row);
/// group table plot button
void runGroupTablePlotButton();
/// group table plot button
void runPairTablePlotButton();
/// Save grouping button
void runSaveGroupButton();
/// Load grouping button
void runLoadGroupButton();
/// Clear grouping button
void runClearGroupingButton();
/// User select instrument
void userSelectInstrument(const QString& prefix);
/// Hide/show MantidPlot toolbars
void setToolbarsHidden(bool hidden);
/// Run the plot button on the home tab.
void runFrontPlotButton();
/// Creates a plot of selected group/pair.
void plotSelectedItem();
///
void runFrontGroupGroupPairComboBox(int index);
/// Link to the wiki for the home tab
void muonAnalysisHelpClicked();
/// Link to the wiki for the grouping tab.
void muonAnalysisHelpGroupingClicked();
/// Check to see if the user want to append the previous run and set accordingly
void checkAppendingPreviousRun();
/// Check to see if the user want to append the next run and set accordingly
void checkAppendingNextRun();
/// When the tab has changed.
void changeTab(int);
/// Update the plot based on changes on the front page.
void homeTabUpdatePlot();
/// Update the group plot based on changes on the group page.
void groupTabUpdateGroup();
/// Update the pair plot based on changes on the group page.
void groupTabUpdatePair();
/// Update the pair plot based on changes on the group page.
void settingsTabUpdatePlot();
/// Updates the style of the current plot according to actual parameters on settings tab.
void updateCurrentPlotStyle();
/// Checks whether plots should be auto-updated when some settings change.
bool isAutoUpdateEnabled();
/// Whether Overwrite option is enabled on the Settings tab.
bool isOverwriteEnabled();
/// Checks if the plot for the workspace does exist.
bool plotExists(const QString& wsName);
/// Enable PP tool for the plot of the given WS
void selectMultiPeak(const QString& wsName);
/// Disable tools for all the graphs within MantidPlot
void disableAllTools();
/// Hides all the plot windows (MultiLayer ones)
void hideAllPlotWindows();
/// Shows all the plot windows (MultiLayer ones)
void showAllPlotWindows();
/// Called when the plot function has been changed on the home page.
void changeHomeFunction();
/// Change what type of deadtime to use and the options available for the user's choice.
void changeDeadTimeType(int);
/// Change to the dead time file, make sure graph is updated next time it is plotted.
void deadTimeFileSelected();
/// Updates the enabled-state and value of Time Zero using "auto" check-box state
void setTimeZeroState(int checkBoxState = -1);
/// Updates the enabled-state and value of First Good Data using "auto" check-box state
void setFirstGoodDataState(int checkBoxState = -1);
/// Saves the value of the widget which called the slot
void saveWidgetValue();
/// Opens a sequential fit dialog
void openSequentialFitDialog();
private:
// Types of entities we are dealing with
enum ItemType { Pair, Group };
// Possible plot types users might request
enum PlotType { Asymmetry, Counts, Logorithm };
// Types of periods
enum PeriodType { First, Second };
/// Initialize local Python environment
void initLocalPython();
/// Initialize the layout
void initLayout();
/// Set start up interface look
void startUpLook();
/// Change the connected data name
void setCurrentDataName(const QString& name);
/// Executed when interface gets hidden or closed
void hideEvent(QHideEvent *e);
/// Executed when interface gets shown
void showEvent(QShowEvent *e);
/// Input file changed - update GUI accordingly
void inputFileChanged(const QStringList& filenames);
/// Set whether the loading buttons and MWRunFiles widget are enabled.
void allowLoading(bool enabled);
/// Return the pair which is in focus and -1 if none
int pairInFocus();
/// is grouping set
bool isGroupingSet();
/// Crop/rebins/offsets the workspace according to interface settings.
MatrixWorkspace_sptr prepareAnalysisWorkspace(MatrixWorkspace_sptr ws, bool isRaw);
/// Creates workspace for specified group/pair and plots it
void plotItem(ItemType itemType, int tableRow, PlotType plotType);
/// Creates workspace ready for analysis and plotting
MatrixWorkspace_sptr createAnalysisWorkspace(ItemType itemType, int tableRow, PlotType type,
bool isRaw = false);
/// Returns PlotType as chosen using given selector
PlotType parsePlotType(QComboBox* selector);
/// Finds a name for new analysis workspace
std::string getNewAnalysisWSName(const std::string& runLabel, ItemType itemType, int tableRow,
PlotType plotType);
/// Selects a workspace from the group according to what is selected on the interface for the period
MatrixWorkspace_sptr getPeriodWorkspace(PeriodType periodType, WorkspaceGroup_sptr group);
/// Update front
void updateFront();
/// Update front anc pair combo box
void updateFrontAndCombo();
/// Updates widgets related to period algebra
void updatePeriodWidgets(int numPeriods);
/// Calculate number of detectors from string of type 1-3, 5, 10-15
int numOfDetectors(const std::string& str) const;
void changeCurrentRun(std::string& workspaceGroupName);
/// is string a number?
bool isNumber(const std::string& s) const;
/// Clear tables and front combo box
void clearTablesAndCombo();
/// Adds the workspaces in a range.
void plusRangeWorkspaces();
/// Delete ranged workspaces.
void deleteRangedWorkspaces();
/// Get group workspace name
QString getGroupName();
/// Get a name for the ranged workspace.
std::string getRangedName();
/// Check if grouping in table is consistent with data file
std::string isGroupingAndDataConsistent();
///Return true if data are loaded
bool areDataLoaded();
/// Return number of pairs
int numPairs();
/// Return number of groups defined (not including pairs)
int numGroups();
/// Returns custom dead time table file name as set on the interface
std::string deadTimeFilename();
/// Loads dead time table (group of tables) from the file.
Workspace_sptr loadDeadTimes(const std::string& filename);
/// Creates and algorithm with all the properties set according to widget values on the interface
Algorithm_sptr createLoadAlgorithm();
/// Plots specific WS spectrum (used by plotPair and plotGroup)
void plotSpectrum(const QString& wsName, const int wsIndex, bool logScale = false);
/// Get current plot style parameters. wsName and wsIndex are used to get default values if
/// something is not specified
QMap<QString, QString> getPlotStyleParams(const QString& wsName, const int wsIndex);
/// get period labels
QStringList getPeriodLabels() const;
// The form generated by Qt Designer
Ui::MuonAnalysis m_uiForm;
/// group plot functions
QStringList m_groupPlotFunc;
/// pair plot functions
QStringList m_pairPlotFunc;
/// The last directory that was viewed
QString m_last_dir;
/// Name of the loaded workspace
std::string m_workspace_name;
/// Name of the loaded AND grouped workspace
std::string m_grouped_name;
/// name of the loaded data
QString m_currentDataName;
/// which group table row has the user last clicked on
int m_groupTableRowInFocus;
/// which pair table row has the user last clicked on
int m_pairTableRowInFocus;
/// Widget of the current tab
QWidget* m_currentTab;
/// used to test that a new filename has been entered
QStringList m_previousFilenames;
/// List of current group names
std::vector<std::string> m_groupNames;
/// Deal with input file changes.
void handleInputFileChanges();
///
void updatePairTable();
/// Currently selected instrument
QString m_curInterfaceSetup;
/// tell which group is in which row
std::vector<int> m_pairToRow;
/// tell which group is in which row
std::vector<int> m_groupToRow;
///
void checkIf_ID_dublicatesInTable(const int row);
/// Return the group-number for the group in a row.
/// Return -1 if invalid group in row
int getGroupNumberFromRow(int row);
/// Return the pair-number for the pair in a row.
/// Return -1 if invalid pair in row
int getPairNumberFromRow(int row);
/// first good bin returned in ms
QString firstGoodBin();
/// According to Plot Options what is the time to plot from in ms
double plotFromTime();
/// According to Plot Options what is the time to plot to in ms
double plotToTime();
/// time zero returned in ms
double timeZero();
/// title of run
std::string m_title;
/// group defaults are saved to
QString m_settingsGroup;
/// Boolean to show whether the gui is being updated
bool m_updating;
/// Flag to indicate that grouping table is being updated
bool m_updatingGrouping;
/// Boolean to show when data has been loaded. (Can't auto-update data that hasn't been loaded)
bool m_loaded;
/// If the dead times have changed.
bool m_deadTimesChanged;
/// The working run or directory displayed in mwRunFiles
QString m_textToDisplay;
/// Load auto saved values
void loadAutoSavedValues(const QString& group);
/// connect the settings for the fit function to their respective slots
void loadFittings();
/// Add or take one away from the range of files
void setAppendingRun(int inc);
/// change and load the run depending on the value passed as a parameter
void changeRun(int amountToChange);
/// Separate the muon file. The current File will remove the path (i.e MUSR002413.nxs)
void separateMuonFile(QString & filePath, QString & currentFile, QString & run, int & runSize);
/// Include the 0's fromt eh beginning of the file that were lost in conversion from QString to int
void getFullCode(int originalSize, QString & run);
/// Setup the signals for updating
void connectAutoUpdate();
/// Setup connects for saving values using QSettings
void connectAutoSave();
/// Saves the value of the widget which called the slot
void loadWidgetValue(QWidget* target, const QVariant& defaultValue);
// Groups loaded workspace (m_workspace_name)
void groupLoadedWorkspace(ITableWorkspace_sptr detGroupingTable = ITableWorkspace_sptr());
/// Parses grouping information from the UI table.
ITableWorkspace_sptr parseGrouping();
/// Updated UI table using the grouping information provided.
void setGrouping(ITableWorkspace_sptr detGroupingTable);
/// Updates UI grouping table - creates dummy grouping
void setDummyGrouping(Instrument_const_sptr instrument);
/// Updates UI grouping table using default grouping of the instrument
void setGroupingFromIDF(Instrument_const_sptr instrument, const std::string& mainFieldDirection);
/// handles option tab work
MantidQt::CustomInterfaces::Muon::MuonAnalysisOptionTab* m_optionTab;
/// handles fit data work
MantidQt::CustomInterfaces::Muon::MuonAnalysisFitDataTab* m_fitDataTab;
/// handles result table tab work
MantidQt::CustomInterfaces::Muon::MuonAnalysisResultTableTab* m_resultTableTab;
/// Time Zero as loaded from Data file
double m_dataTimeZero;
/// First Good Data time as loaded from Data file
double m_dataFirstGoodData;
static const QString NOT_AVAILABLE;
//A reference to a logger
static Mantid::Kernel::Logger & g_log;
/// Creates new double validator which accepts numbers in standard notation only.
static QDoubleValidator* createDoubleValidator(QObject* parent);
};
}
}
#endif //MANTIDQTCUSTOMINTERFACES_MUONANALYSIS_H_