\(\renewcommand\AA{\unicode{x212B}}\)

CentroidPeaksMD v2

../_images/ImageNotFound.png

Enable screenshots using DOCS_SCREENSHOTS in CMake

Summary

Find the centroid of single-crystal peaks in a MDEventWorkspace, in order to refine their positions.

See Also

IntegratePeaksMD, CentroidPeaks

Properties

Name

Direction

Type

Default

Description

InputWorkspace

Input

MDEventWorkspace

Mandatory

An input MDEventWorkspace.

PeakRadius

Input

number

1

Fixed radius around each peak position in which to calculate the centroid.

PeaksWorkspace

Input

IPeaksWorkspace

Mandatory

A PeaksWorkspace containing the peaks to centroid.

OutputWorkspace

Output

IPeaksWorkspace

Mandatory

The output PeaksWorkspace will be a copy of the input PeaksWorkspace with the peaks’ positions modified by the new found centroids.

Description

This algorithm starts with a PeaksWorkspace containing the expected positions of peaks in reciprocal space. It calculates the centroid of the peak by calculating the average of the coordinates of all events within a given radius of the peak, weighted by the weight (signal) of the event.

Usage

Example - CentroidPeaksMD:

The code iteslef works but disabled from doc tests as takes too long to complete. User should provide its own event nexus file instead of TOPAZ_3132_event.nxs used within this example. The original TOPAZ_3132_event.nxs file is available in Mantid system tests repository.

The example shows how applying centroid peaks changes the peak posisions previously calculated by FindPeaksMD algorithm.

 1#.. testcode:: exCentroidPeaksMD
 2
 3def print_WSDifference(pTWS1,pTWS2,nRows):
 4       ''' Method to print difference between two table workspaces before and after applying CentroidPeaks '''
 5       # columns to compare
 6       tab_names=['RunNumber','DetID','Energy','DSpacing','QLab','QSample']
 7       common = tab_names[0:2];
 8    long = tab_names[-2:];
 9
10
11       for name in tab_names:
12           if name in common :
13                print("| {0:>10}  ".format(name))
14           else:
15               if name in long:
16                    print("|FindPeaksMD found (old):{0:>7} |IntegrEllipsoids (new): {0:>7}  ".format(name))
17               else:
18                   ntp = name;
19                   if len(ntp )>6:
20                       ntp = ntp[0:6]
21                   print("| old {0:>6} | new {0:>6}  ".format(ntp))
22       print("|\n" )
23
24       for i in xrange(0,nRows):
25           for name in tab_names:
26                 col1 = pTWS1.column(name);
27                 data1_toPr=col1[i]
28                 col2 = pTWS2.column(name);
29                 data2_toPr=col2[i]
30                 if name in common :
31                      print("| {0:>10}  ".format(data1_toPr))
32                 else:
33                      if name in long:
34                         print("| {0:>30} | {1:>30}  ".format(data1_toPr,data2_toPr))
35                      else:
36                         print("| {0:>10.2f} | {1:>10.2f}  ".format(data1_toPr,data2_toPr))
37
38           print("|\n ")
39
40
41# load test workspace
42Load(Filename=r'TOPAZ_3132_event.nxs',OutputWorkspace='TOPAZ_3132_event',LoadMonitors='1')
43
44# build peak workspace necessary for IntegrateEllipsoids algorithm to work
45ConvertToMD(InputWorkspace='TOPAZ_3132_event',QDimensions='Q3D',dEAnalysisMode='Elastic',Q3DFrames='Q_sample',LorentzCorrection='1',OutputWorkspace='TOPAZ_3132_md',\
46MinValues='-25,-25,-25',MaxValues='25,25,25',SplitInto='2',SplitThreshold='50',MaxRecursionDepth='13',MinRecursionDepth='7')
47
48# get initial peak workspace
49peaks=FindPeaksMD(InputWorkspace='TOPAZ_3132_md',PeakDistanceThreshold='0.37680',MaxPeaks='50',DensityThresholdFactor='100',OutputWorkspace='TOPAZ_3132_peaks')
50
51# refine peaks position with centroid peaks
52peaks2=CentroidPeaksMD(InputWorkspace='TOPAZ_3132_md', PeaksWorkspace='TOPAZ_3132_peaks', OutputWorkspace='TOPAZ_3132_peaks2')
53
54print_WSDifference(peaks,peaks2,10)
55
56
57**Output:**
 1#.. testoutput:: exCentroidPeaksMD
 2
 3
 4|  RunNumber  |      DetID  | old Energy | new Energy  | old DSpaci | new DSpaci  |FindPeaksMD found (old):   QLab |IntegrEllipsoids (new):    QLab  |FindPeaksMD found (old):QSample |IntegrEllipsoids (new): QSample  |
 5|       3132  |    1124984  |       8.49 |      10.39  |       2.02 |       1.93  |      [1.57771,1.21779,2.37854] |       [1.9157,1.15022,2.37669]  |  [2.99396,0.815958,0.00317344] |    [3.13041,0.861402,0.316416]  |
 6|       3132  |    1156753  |      18.82 |      18.87  |       1.30 |       1.29  |      [2.48964,1.45725,3.88666] |      [2.50792,1.41823,3.91448]  |     [4.52618,1.71025,0.129461] |     [4.52916,1.75746,0.149293]  |
 7|       3132  |    1141777  |      28.09 |      29.63  |       1.05 |       1.04  |      [2.60836,2.31423,4.86391] |        [2.9387,2.15218,4.7974]  |    [5.69122,1.79492,-0.452799] |   [5.72802,1.86148,-0.0867018]  |
 8|       3132  |    1125241  |      33.86 |      32.09  |       1.01 |       1.01  |      [3.15504,2.42573,4.75121] |      [3.12135,2.20547,4.87426]  |    [5.97829,1.63473,0.0118744] |     [5.9025,1.87759,0.0200907]  |
 9|       3132  |    1170598  |      34.12 |      32.63  |       0.95 |       0.96  |      [3.43363,1.70178,5.39301] |       [3.2557,1.75038,5.41104]  |     [6.07726,2.59962,0.281759] |     [6.02352,2.57854,0.105647]  |
10|       3132  |    1214951  |      22.79 |      19.55  |       1.68 |       1.67  |      [2.73683,1.43808,2.11574] |      [2.60506,1.43592,2.30563]  |      [3.5786,0.470838,1.00329] |    [3.62222,0.607039,0.821705]  |
11|       3132  |    1207827  |      27.89 |      29.54  |       1.32 |       1.31  |      [2.80324,2.29519,3.09134] |      [2.99683,2.18047,3.05302]  |     [4.71517,0.554412,0.37714] |    [4.72528,0.607846,0.598834]  |
12|       3132  |    1232949  |      53.28 |      57.02  |       0.93 |       0.93  |      [4.29033,2.63319,4.46168] |      [4.40869,2.69431,4.34027]  |      [6.52658,1.27985,1.00646] |       [6.5525,1.15043,1.12919]  |
13|       3132  |    1189484  |      63.42 |      60.85  |       0.96 |       0.96  |      [4.02414,3.39659,3.83664] |      [4.15914,3.15181,3.95843]  |     [6.4679,0.298896,0.726133] |    [6.46553,0.557683,0.887368]  |
14|       3132  |    1218337  |      79.81 |      87.16  |       0.77 |       0.77  |      [4.96622,3.61607,5.32554] |      [5.17998,3.67105,5.16175]  |     [7.99244,1.19363,0.892655] |      [8.03942,1.03829,1.11448]  |

Categories: AlgorithmIndex | MDAlgorithms\Peaks

Source

C++ header: CentroidPeaksMD2.h

C++ source: CentroidPeaksMD2.cpp