-
Notifications
You must be signed in to change notification settings - Fork 122
/
MantidEVWorker.cpp
1146 lines (989 loc) · 38.5 KB
/
MantidEVWorker.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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <sstream>
#include "MantidQtCustomInterfaces/MantidEVWorker.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/Workspace.h"
#include "MantidAPI/IEventWorkspace.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/IPeak.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidKernel/EmptyValues.h"
#include <exception>
namespace MantidQt
{
namespace CustomInterfaces
{
using namespace Mantid::Kernel;
using namespace Mantid::API;
// Initialize the logger
Logger& MantidEVWorker::g_log = Logger::get("MantidEV");
/**
* Default constructor
*/
MantidEVWorker::MantidEVWorker()
{
}
/**
* Default destructor
*/
MantidEVWorker::~MantidEVWorker()
{
}
/**
* Utility method to get the type of a workspace. If the named workspace
* is NOT present in the ADS a zero length string is returned. If the named
* workspace is in the ADS, the id string for the workspace is returned.
* For example for a PeaksWorkspace, the id string returned is
* "PeaksWorkspace".
*
* @param ws_name The name of the workspace
*
* @return The workspace id, or and zero length string if the workspace
* doesn't exist.
*/
std::string MantidEVWorker::workspaceType( const std::string & ws_name )
{
const auto& ADS = AnalysisDataService::Instance();
if ( !ADS.doesExist( ws_name ) )
return std::string("");
Workspace_const_sptr outWS = ADS.retrieveWS<Workspace>(ws_name);
return outWS->id();
}
/**
* Utility method to check if a name is the name of an MDWorkspace.
*
* @param md_ws_name The name of the workspace
*
* @return true if the named workspace exists and is an MDWorkspace.
*/
bool MantidEVWorker::isMDWorkspace( const std::string & md_ws_name )
{
std::string ws_type = workspaceType(md_ws_name);
if ( ws_type.length() == 0 )
return false;
if ( ws_type != "MDEventWorkspace<MDEvent,3>" && ws_type != "MDHistoWorkspace" )
return false;
return true;
}
/**
* Utility method to check if a name is the name of a PeaksWorkspace.
*
* @param peaks_ws_name The name of the workspace
*
* @return true if the named workspace exists and is a PeaksWorkspace.
*/
bool MantidEVWorker::isPeaksWorkspace( const std::string & peaks_ws_name )
{
std::string ws_type = workspaceType(peaks_ws_name);
if ( ws_type.length() == 0 )
return false;
if ( ws_type != "PeaksWorkspace" )
return false;
return true;
}
/**
* Utility method to check if a name is the name of an EventWorkspace.
*
* @param event_ws_name The name of the workspace
*
* @return true if the named workspace exists and is an EventWorkspace.
*/
bool MantidEVWorker::isEventWorkspace( const std::string & event_ws_name )
{
std::string ws_type = workspaceType(event_ws_name);
if ( ws_type.length() == 0 )
return false;
if ( ws_type != "EventWorkspace" )
{
return false;
}
return true;
}
/**
* Load the specified NeXus event file into the specified EventWorkspace
* and convert it to the specified MD workspace.
*
* @param file_name Name of the NeXus file to load
* @param ev_ws_name Name of the event workspace to create
* @param md_ws_name Name of the MD workspace to create
* @param minQ The smallest absolute value of any component
* of Q to include. When ConvertToMD is called,
* @param maxQ The largest absolute value of any component
* of Q to include. When ConvertToMD is called,
* MinValues = -maxQ,-maxQ,-maxQ and
* MaxValues = maxQ, maxQ, maxQ
* @param do_lorentz_corr Set true to do the Lorentz correction when
* converting to reciprocal space.
* @param load_data Set true to load data.
* @param load_det_cal Set true to call LoadIsawDetCal after loading
* the event file.
* @param det_cal_file Fully qualified name of the .DetCal file.
* @param det_cal_file2 Fully qualified name of the second .DetCal
* file for the second panel on SNAP.
*
* @return true if the file was loaded and MD workspace was
* successfully created.
*/
bool MantidEVWorker::loadAndConvertToMD( const std::string & file_name,
const std::string & ev_ws_name,
const std::string & md_ws_name,
const double minQ,
const double maxQ,
const bool do_lorentz_corr,
const bool load_data,
const bool load_det_cal,
const std::string & det_cal_file,
const std::string & det_cal_file2 )
{
try
{
IAlgorithm_sptr alg;
if (load_data)
{
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("Load");
alg->setProperty("Filename",file_name);
alg->setProperty("OutputWorkspace",ev_ws_name);
alg->setProperty("Precount",true);
alg->setProperty("LoadMonitors",true);
if ( !alg->execute() )
return false;
if ( load_det_cal )
{
alg = AlgorithmManager::Instance().create("LoadIsawDetCal");
alg->setProperty( "InputWorkspace", ev_ws_name );
alg->setProperty( "Filename", det_cal_file );
alg->setProperty( "Filename2", det_cal_file2 );
if ( !alg->execute() )
return false;
}
}
std::ostringstream min_str;
if (minQ != Mantid::EMPTY_DBL())
min_str << minQ << "," << minQ << "," << minQ;
else
min_str << "-" << maxQ << ",-" << maxQ << ",-" << maxQ;
std::ostringstream max_str;
max_str << maxQ << "," << maxQ << "," << maxQ;
alg = AlgorithmManager::Instance().create("ConvertToMD");
alg->setProperty("InputWorkspace",ev_ws_name);
alg->setProperty("OutputWorkspace",md_ws_name);
alg->setProperty("OverwriteExisting",true);
alg->setProperty("QDimensions","Q3D");
alg->setProperty("dEAnalysisMode","Elastic");
alg->setProperty("QConversionScales","Q in A^-1");
alg->setProperty("Q3DFrames","Q_sample");
alg->setProperty("LorentzCorrection",do_lorentz_corr);
alg->setProperty("MinValues",min_str.str());
alg->setProperty("MaxValues",max_str.str());
alg->setProperty("SplitInto","2");
alg->setProperty("SplitThreshold","50");
alg->setProperty("MaxRecursionDepth","13");
alg->setProperty("MinRecursionDepth","7");
if ( !alg->execute() )
return false;
}
catch( std::exception &e)
{
g_log.error()<<"Error:" << e.what() <<std::endl;
return false;
}
catch(...)
{
g_log.error()<<"Error: Could Not load file and convert to MD" <<std::endl;
return false;
}
return true;
}
/**
* Find peaks in the specified MD workspace and save them in the
* specified peaks workspace.
*
* @param md_ws_name Name of the MD workspace to use
* @param peaks_ws_name Name of the peaks workspace to create
*
* @param max_abc Estimate of the maximum real space
* edge length. This is used to get an
* estimate of the minimum peak separation
* in reciprocal space.
* @param num_to_find The number of peaks to find.
* @param min_intensity Sets the minimum value to consider an
* MD box to be a possible peak. If this
* is 10000, only boxes with intensity 10000 times
* the average intensity will be considered.
*
* @return true if FindPeaksMD completed successfully.
*/
bool MantidEVWorker::findPeaks( const std::string & md_ws_name,
const std::string & peaks_ws_name,
double max_abc,
size_t num_to_find,
double min_intensity )
{
try
{
// Estimate a lower bound on the distance between
// based on the maximum real space cell edge
double min_separation = 0.9 * 6.28 / max_abc;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("FindPeaksMD");
alg->setProperty("InputWorkspace",md_ws_name);
alg->setProperty("PeakDistanceThreshold", min_separation);
alg->setProperty("MaxPeaks",(int64_t)num_to_find);
alg->setProperty("DensityThresholdFactor",min_intensity);
alg->setProperty("OutputWorkspace", peaks_ws_name );
if ( alg->execute() )
return true;
}
catch( std::exception &e)
{
g_log.error()<<"Error:" << e.what() <<std::endl;
return false;
}
catch(...)
{
g_log.error()<<"Error: Could Not findPeaks" <<std::endl;
return false;
}
return false;
}
/**
* Load the specified peaks workspace from the specified peaks file.
*
* @param peaks_ws_name The name of the peaks workspace to load/create.
* @param file_name The name of the peaks file to load.
*
* @return true if LoadIsawPeaks completed successfully.
*/
bool MantidEVWorker::loadIsawPeaks( const std::string & peaks_ws_name,
const std::string & file_name )
{
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("LoadIsawPeaks");
alg->setProperty("Filename",file_name );
alg->setProperty("OutputWorkspace", peaks_ws_name );
if ( alg->execute() )
return true;
return false;
}
/**
* Load the specified peaks workspace to the specified peaks file.
*
* @param peaks_ws_name The name of the peaks workspace to save.
* @param file_name The name of the peaks file to write to.
* @param append Append the peaks from the peaks workspace
* onto the specified peaks file, if append
* is true and the peaks file already exists.
*
* @return true if SaveIsawPeaks completed successfully.
*/
bool MantidEVWorker::saveIsawPeaks( const std::string & peaks_ws_name,
const std::string & file_name,
bool append )
{
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("SaveIsawPeaks");
alg->setProperty("InputWorkspace", peaks_ws_name );
alg->setProperty("AppendFile", append );
alg->setProperty("Filename",file_name );
if ( alg->execute() )
return true;
return false;
}
/**
* Find an optimized UB matrix that indexes the peaks in the specified
* peaks workspace.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param min_abc Lower bound for the real space edge lengths.
* @param max_abc Upper bound for the real space edge lengths.
* @param tolerance The tolerance on hkl values to use when
* determining whether or not a peak is indexed.
*
* @return true if FindUBusingFFT completed successfully.
*/
bool MantidEVWorker::findUBUsingFFT( const std::string & peaks_ws_name,
double min_abc,
double max_abc,
double tolerance )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("FindUBUsingFFT");
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("MinD",min_abc);
alg->setProperty("MaxD",max_abc);
alg->setProperty("Tolerance",tolerance);
if ( alg->execute() )
{
return true;
}
return false;
}
/**
* Find an optimized UB matrix from the indexed peaks in the specified
* peaks workspace.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param tolerance Tolerance for the peak finding.
*
* @return true if FindUBusingIndexedPeaks completed successfully.
*/
bool MantidEVWorker::findUBUsingIndexedPeaks(const std::string & peaks_ws_name, double tolerance )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("FindUBUsingIndexedPeaks");
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("Tolerance",tolerance);
if ( alg->execute() )
return true;
return false;
}
/**
* Load a UB matrix from the specified ISAW peaks file into the specified
* peaks workspace.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param file_name The name of the ISAW peaks file to load.
*
* @return true if LoadIsawUB completed successfully.
*/
bool MantidEVWorker::loadIsawUB( const std::string & peaks_ws_name,
const std::string & file_name)
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("LoadIsawUB");
alg->setProperty("InputWorkspace",peaks_ws_name);
alg->setProperty("Filename",file_name);
alg->setProperty("CheckUMatrix",true);
if ( alg->execute() )
return true;
return false;
}
/**
* Save the UB matrix from the specified peaks workspace into the specified
* ISAW matrix file.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param file_name The name of the ISAW matrix file to write.
*
* @return true if SaveIsawUB completed successfully.
*/
bool MantidEVWorker::saveIsawUB( const std::string & peaks_ws_name,
const std::string & file_name)
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("SaveIsawUB");
alg->setProperty("InputWorkspace",peaks_ws_name);
alg->setProperty("Filename",file_name);
if ( alg->execute() )
return true;
return false;
}
/**
* Adjust the goniometer angles in the specified peaks workspace to
* maximize the number of peaks that are indexed with the current UB
* matrix.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param max_change The maximum change allowed for any
* goniometer angle, in degrees.
*
* @return true if the OptimizeCrystalPlacement algorithm completes
* successfully.
*/
bool MantidEVWorker::optimizePhiChiOmega( const std::string & peaks_ws_name,
double max_change )
{
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("OptimizeCrystalPlacement");
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("KeepGoniometerFixedfor","");
alg->setProperty("ModifiedPeaksWorkspace",peaks_ws_name);
std::string info_table = "_info";
info_table = peaks_ws_name + info_table;
alg->setProperty("FitInfoTable",info_table);
alg->setProperty("AdjustSampleOffsets",false);
alg->setProperty("OptimizeGoniometerTilt",false);
alg->setProperty("MaxAngularChange",max_change);
alg->setProperty("MaxIndexingError",0.20);
alg->setProperty("MaxHKLPeaks2Use",-1.0);
alg->setProperty("MaxSamplePositionChange_meters",0.05);
if ( alg->execute() )
return true;
return false;
}
/**
* Actually index the peaks in the specified peaks workspace using the
* current UB matrix in the workspace.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param tolerance The tolerance on hkl to use while indexing.
* @param round_hkls If true, the computed hkl values will be
* rounded to the nearest integer value.
*
* @return true if the IndexPeaks algorithm completes successfully.
*/
bool MantidEVWorker::indexPeaksWithUB( const std::string & peaks_ws_name,
double tolerance,
bool round_hkls )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("IndexPeaks");
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("Tolerance",tolerance);
alg->setProperty("RoundHKLs",round_hkls);
if ( alg->execute() )
return true;
return false;
}
/**
* Display the possible conventional cells corresponding to the current
* UB. NOTE: This only makes sense if the current UB matrix corresponds
* to the Niggli reduced cell.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param max_scalar_error The maximum error in the cell scalars that
* is allowed for a possible cell to be listed.
* @param best_only If true, only the best fitting cell of any
* particular type will be displayed.
*
* @return true if the ShowPossibleCells algorithm completes successfully.
*/
bool MantidEVWorker::showCells( const std::string & peaks_ws_name,
double max_scalar_error,
bool best_only )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("ShowPossibleCells");
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("MaxScalarError",max_scalar_error);
alg->setProperty("BestOnly",best_only);
if ( alg->execute() )
return true;
return false;
}
/**
* Change the UB matrix and indexing from the current Niggli reduced
* cell to the specified cell type and centering.
* NOTE: This only makes sense if the current UB matrix corresponds
* to the Niggli reduced cell.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param cell_type String with the cell type, such as "Cubic".
* @param centering String with the centering such as "F".
*
* @return true if the SelectCellOfType algorithm completes successfully.
*/
bool MantidEVWorker::selectCellOfType( const std::string & peaks_ws_name,
const std::string & cell_type,
const std::string & centering )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("SelectCellOfType");
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("CellType",cell_type);
alg->setProperty("Centering",centering);
alg->setProperty("Apply",true);
alg->setProperty("tolerance",0.12);
if ( alg->execute() )
return true;
return false;
}
/**
* Change the UB matrix and indexing from the current Niggli reduced
* cell to the cell with the specified form number.
* NOTE: This only makes sense if the current UB matrix corresponds
* to the Niggli reduced cell.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param form_num The form number, 1..44.
*
* @return true if the SelectCellWithForm algorithm completes successfully.
*/
bool MantidEVWorker::selectCellWithForm( const std::string & peaks_ws_name,
size_t form_num )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("SelectCellWithForm");
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("FormNumber",(int)form_num);
alg->setProperty("Apply",true);
alg->setProperty("tolerance",0.12);
if ( alg->execute() )
return true;
return false;
}
/**
* Change the UB matrix and indexing using the specified tranformation
* that maps the current hkl vectors to the desired hkl values.
*
* @param peaks_ws_name The name of the peaks workspace.
* @param row_1_str String with the three entries from the
* first row of the matrix.
* @param row_2_str String with the three entries from the
* second row of the matrix.
* @param row_3_str String with the three entries from the
* third row of the matrix.
*
* @return true if the TransformHKL algorithm completes successfully.
*/
bool MantidEVWorker::changeHKL( const std::string & peaks_ws_name,
const std::string & row_1_str,
const std::string & row_2_str,
const std::string & row_3_str )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
std::string transf_string = row_1_str + "," + row_2_str + "," + row_3_str;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("TransformHKL");
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("HKLTransform",transf_string);
if ( alg->execute() )
return true;
return false;
}
/**
* Integrate the peaks from the specified peaks workspace by generating
* raw unweighted events in reciprocal space from the specified events
* workspace and applying the IntegratePeaksMD algorithm to the raw
* event MD workspace.
*
* @param peaks_ws_name The name of the peaks workspace with the peaks
* to integrate.
* @param event_ws_name The name of the event workspace to use when
* generating the temporary raw MD event workspace.
* @param peak_radius The radius of the peak region.
* @param inner_radius The radius of the inner surface of the background
* region.
* @param outer_radius The radius of the outer surface of the background
* region.
* @param integrate_edge If true, integrate peaks for which the sphere
* goes off the edge of the detector.
* @param use_cylinder_integration Set true to use cylinder integration
* @param cylinder_length Set the cylinder length
* @param cylinder_percent_bkg Percentage background to use in the
* cylinder
* @param cylinder_profile_fit String to some use.
*
* @return true if the unweighted workspace was successfully created and
* integrated using IntegratePeaksMD.
*/
bool MantidEVWorker::sphereIntegrate( const std::string & peaks_ws_name,
const std::string & event_ws_name,
double peak_radius,
double inner_radius,
double outer_radius,
bool integrate_edge,
bool use_cylinder_integration,
double cylinder_length,
double cylinder_percent_bkg,
const std::string & cylinder_profile_fit)
{
try
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
if ( !isEventWorkspace( event_ws_name ) )
return false;
std::string temp_MD_ws_name = "__MantidEVWorker_sphere_integrate_temp_MD_ws";
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("ConvertToMD");
alg->setProperty("InputWorkspace",event_ws_name);
alg->setProperty("OutputWorkspace",temp_MD_ws_name);
alg->setProperty("OverwriteExisting",true);
alg->setProperty("QDimensions","Q3D");
alg->setProperty("dEAnalysisMode","Elastic");
alg->setProperty("QConversionScales","Q in A^-1");
alg->setProperty("Q3DFrames","Q_sample");
alg->setProperty("UpdateMasks",false);
alg->setProperty("LorentzCorrection",false);
alg->setProperty("MinValues","-30,-30,-30");
alg->setProperty("MaxValues","30,30,30");
alg->setProperty("SplitInto","2,2,2");
alg->setProperty("SplitThreshold",200);
alg->setProperty("MaxRecursionDepth",10);
alg->setProperty("MinRecursionDepth",7);
std::cout << "Making temporary MD workspace" << std::endl;
if ( !alg->execute() )
return false;
std::cout << "Made temporary MD workspace...OK" << std::endl;
alg = AlgorithmManager::Instance().create("IntegratePeaksMD");
alg->setProperty("InputWorkspace", temp_MD_ws_name);
alg->setProperty("PeakRadius",peak_radius);
alg->setProperty("BackgroundInnerRadius",inner_radius);
alg->setProperty("BackgroundOuterRadius",outer_radius);
alg->setProperty("PeaksWorkspace",peaks_ws_name);
alg->setProperty("OutputWorkspace",peaks_ws_name);
alg->setProperty("ReplaceIntensity",true);
alg->setProperty("IntegrateIfOnEdge",integrate_edge);
alg->setProperty("Cylinder",use_cylinder_integration);
alg->setProperty("CylinderLength",cylinder_length);
alg->setProperty("PercentBackground",cylinder_percent_bkg);
alg->setProperty("ProfileFunction",cylinder_profile_fit);
std::cout << "Integrating temporary MD workspace" << std::endl;
bool integrate_OK = alg->execute();
auto& ADS = AnalysisDataService::Instance();
std::cout << "Removing temporary MD workspace" << std::endl;
ADS.remove( temp_MD_ws_name );
if ( integrate_OK )
{
std::cout << "Integrated temporary MD workspace...OK" << std::endl;
return true;
}
std::cout << "Integrated temporary MD workspace FAILED" << std::endl;
return false;
}
catch( std::exception &e)
{
g_log.error()<<"Error:" << e.what() <<std::endl;
return false;
}
catch(...)
{
g_log.error()<<"Error: Could Not Integrated temporary MD workspace" <<std::endl;
return false;
}
}
/**
* Integrate the peaks from the specified peaks workspace by applying
* the PeakIntegration algorithm to the event workspace.
*
* @param peaks_ws_name The name of the peaks workspace with the
* peaks to integrate.
* @param event_ws_name The name of the event workspace to use.
* @param rebin_param_str String listing the rebinning parameters
* to use when forming the event workspace
* into a histogram workspace.
* @param n_bad_edge_pix The number of pixels to omit at the edge
* of all detectors.
* @param use_ikeda_carpenter If true, the integrated intensities on
* the time-of-flight slices will be fit
* using the Ikeda-Carpenter function to
* obtain the final integrated intensities.
*
* @return true if the PeakIntegration algorithm completed successfully.
*/
bool MantidEVWorker::fitIntegrate( const std::string & peaks_ws_name,
const std::string & event_ws_name,
const std::string & rebin_param_str,
size_t n_bad_edge_pix,
bool use_ikeda_carpenter )
{
try
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
if ( !isEventWorkspace( event_ws_name ) )
return false;
std::string temp_FIT_ws_name = "__MantidEVWorker_FIT_integration_temp_event_ws";
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("Rebin");
alg->setProperty("InputWorkspace",event_ws_name);
alg->setProperty("OutputWorkspace",temp_FIT_ws_name);
alg->setProperty("Params",rebin_param_str);
alg->setProperty("PreserveEvents",true);
std::cout << "Rebinning event workspace" << std::endl;
if ( !alg->execute() )
return false;
alg = AlgorithmManager::Instance().create("PeakIntegration");
alg->setProperty("InPeaksWorkspace", peaks_ws_name);
alg->setProperty("InputWorkspace", temp_FIT_ws_name);
alg->setProperty("OutPeaksWorkspace", peaks_ws_name);
alg->setProperty("IkedaCarpenterTOF",use_ikeda_carpenter);
alg->setProperty("MatchingRunNo",true);
alg->setProperty("NBadEdgePixels",(int)n_bad_edge_pix);
std::cout << "Integrating temporary Rebinned workspace" << std::endl;
bool integrate_OK = alg->execute();
auto& ADS = AnalysisDataService::Instance();
std::cout << "Removing temporary Rebinned workspace" << std::endl;
ADS.remove( temp_FIT_ws_name );
if ( integrate_OK )
{
std::cout << "Integrated temporary FIT workspace...OK" << std::endl;
return true;
}
std::cout << "Integrated temporary FIT workspace FAILED" << std::endl;
}
catch( std::exception &e)
{
g_log.error()<<"Error:" << e.what() <<std::endl;
return false;
}
catch(...)
{
g_log.error()<<"Error: Could Not Integrated temporary FIT workspace" <<std::endl;
return false;
}
return false;
}
/**
* Integrate the peaks from the specified peaks workspace by applying
* the IntegrateEllipsoids algorithm to the event workspace.
*
* @param peaks_ws_name The name of the peaks workspace with the peaks
* to integrate.
* @param event_ws_name The name of the event workspace to use.
* @param region_radius The radius of the whole spherical region
* enclosing the peak and background ellipsoids.
* @param specify_size If true the sizes of the peak and background
* regions are specified by the last three
* parameters to this method.
* @param peak_size The size of the major axis of the peak ellipsoid.
* @param inner_size The size of the major axis of the inner surface
* of the background ellipsoid.
* @param outer_size The size of the major axis of the outer surface
* of the background ellipsoid.
*
* @return true if the IntegrateEllipsoids algorithm completed successfully.
*/
bool MantidEVWorker::ellipsoidIntegrate( const std::string & peaks_ws_name,
const std::string & event_ws_name,
double region_radius,
bool specify_size,
double peak_size,
double inner_size,
double outer_size )
{
try
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
return false;
if ( !isEventWorkspace( event_ws_name ) )
return false;
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("IntegrateEllipsoids");
alg->setProperty("InputWorkspace", event_ws_name);
alg->setProperty("PeaksWorkspace", peaks_ws_name);
alg->setProperty("RegionRadius",region_radius);
alg->setProperty("SpecifySize",specify_size);
alg->setProperty("PeakSize",peak_size);
alg->setProperty("BackgroundInnerSize",inner_size);
alg->setProperty("BackgroundOuterSize",outer_size);
alg->setProperty("OutputWorkspace",peaks_ws_name);
std::cout << "Running IntegrateEllipsoids" << std::endl;
if ( alg->execute() )
{
std::cout << "IntegrateEllipsoids Executed OK" << std::endl;
return true;
}
std::cout << "IntegrateEllipsoids FAILED" << std::endl;
}
catch( std::exception &e)
{
g_log.error()<<"Error:" << e.what() <<std::endl;
return false;
}
catch(...)
{
g_log.error()<<"Error: Could Not IntegratedEllipsoids" <<std::endl;
return false;
}
return false;
}
/**
* Show the current UB matrix from the specified peaks workspace
* in both the Mantid and ISAW forms.
*
* @param peaks_ws_name The name of the peaks workspace with the UB
* matrix.
*
* @return true if the peaks workspace had a UB matrix to show.
*/
bool MantidEVWorker::showUB( const std::string & peaks_ws_name )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
{
return false;
}
const auto& ADS = AnalysisDataService::Instance();
IPeaksWorkspace_sptr peaks_ws = ADS.retrieveWS<IPeaksWorkspace>(peaks_ws_name);
try
{
char logInfo[200];
Mantid::Geometry::OrientedLattice o_lattice = peaks_ws->mutableSample().getOrientedLattice();
Matrix<double> UB = o_lattice.getUB();
g_log.notice() << std::endl;
g_log.notice() << "Mantid UB = " << std::endl;
sprintf( logInfo,
std::string(" %12.8f %12.8f %12.8f\n %12.8f %12.8f %12.8f\n %12.8f %12.8f %12.8f\n").c_str(),
UB[0][0], UB[0][1], UB[0][2],
UB[1][0], UB[1][1], UB[1][2],
UB[2][0], UB[2][1], UB[2][2] );
g_log.notice( std::string(logInfo) );
g_log.notice() << "ISAW UB = " << std::endl;
sprintf( logInfo,
std::string(" %12.8f %12.8f %12.8f\n %12.8f %12.8f %12.8f\n %12.8f %12.8f %12.8f\n").c_str(),
UB[2][0], UB[0][0], UB[1][0],
UB[2][1], UB[0][1], UB[1][1],
UB[2][2], UB[0][2], UB[1][2] );
g_log.notice( std::string(logInfo) );
double calc_a = o_lattice.a();
double calc_b = o_lattice.b();
double calc_c = o_lattice.c();
double calc_alpha = o_lattice.alpha();
double calc_beta = o_lattice.beta();
double calc_gamma = o_lattice.gamma();
// Show the modified lattice parameters
sprintf( logInfo,
std::string("Lattice Parameters: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f").c_str(),
calc_a, calc_b, calc_c, calc_alpha, calc_beta, calc_gamma);
g_log.notice( std::string(logInfo) );
sprintf( logInfo,
std::string("%19s %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f").c_str(),
"Lattice Errors :",
o_lattice.errora(),o_lattice.errorb(),o_lattice.errorc(),
o_lattice.erroralpha(),o_lattice.errorbeta(),o_lattice.errorgamma());
g_log.notice( std::string( logInfo));
}
catch(...)
{
return false;
}
return true;
}
/**
* Get the current UB matrix from the specified peaks workspace.
*
* @param peaks_ws_name The name of the peaks workspace with the UB
* matrix.
* @param lab_coords If true, multiply the goniometer matrix
* times UB before returning it, so that
* the UB is expressed in lab-coordinates,
* otherwise, return the UB as it is stored
* in the sample.
* @param UB 3x3 matrix of doubles to be filled out with
* the UB matrix if one exists in the specified
* peaks workspace.
* @return true if the UB matrix was found and returned in the UB
* parameter.